一个不完善的可自定义弹出窗体的下拉框
来源:互联网 发布:淘宝店宝贝描述手机版 编辑:程序博客网 时间:2024/06/06 03:45
namespace WindowsFormsApplication19
{
partial class UserControl1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication19
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
this.Invalidated += new InvalidateEventHandler(UserControl1_Invalidated);
}
void UserControl1_Invalidated(object sender, InvalidateEventArgs e)
{
((Control)sender).CreateGraphics().DrawString(temp.ToString(), new Font("sum", 12), new SolidBrush(Color.Black), new PointF(1, 1));
temp++;
}
int temp = 1;
//弹出窗体的位置
private Point GetPopWindowRect()
{
//calculate its position in screen coordinates
Rectangle rect = Bounds;
rect = this.Parent.RectangleToScreen(rect);
Point pt = new System.Drawing.Point(rect.Left, rect.Bottom);
return pt;
}
protected override void OnClick(EventArgs e)
{
{
Button btn = new Button();
PopWindow control = new PopWindow(btn);
control.closedPopWindow += ClosedPopWindow;
control.Show(GetPopWindowRect());
}
}
void control_Closed(object sender, ToolStripDropDownClosedEventArgs e)
{
throw new NotImplementedException();
}
protected override void OnMouseUp(MouseEventArgs e)
{
this.Parent.Text = "up";
Rectangle invalidatedArea = this.ClientRectangle;
System.Windows.Forms.ComboBoxRenderer.DrawTextBox(this.CreateGraphics(), new Rectangle(invalidatedArea.Left,
invalidatedArea.Top, invalidatedArea.Width, invalidatedArea.Height), System.Windows.Forms.VisualStyles.ComboBoxState.Normal);
System.Windows.Forms.ComboBoxRenderer.DrawDropDownButton(this.CreateGraphics(), new Rectangle(
invalidatedArea.Left + invalidatedArea.Width - 20,
invalidatedArea.Top + 2, 18, invalidatedArea.Height - 4), System.Windows.Forms.VisualStyles.ComboBoxState.Normal);
base.OnMouseUp(e);
}
protected override void OnMouseDown(MouseEventArgs e)
{
{
this.Parent.Text = "down";
Rectangle invalidatedArea = this.ClientRectangle;
System.Windows.Forms.ComboBoxRenderer.DrawTextBox(this.CreateGraphics(), new Rectangle(invalidatedArea.Left,
invalidatedArea.Top, invalidatedArea.Width, invalidatedArea.Height), System.Windows.Forms.VisualStyles.ComboBoxState.Pressed);
System.Windows.Forms.ComboBoxRenderer.DrawDropDownButton(this.CreateGraphics(), new Rectangle(
invalidatedArea.Left + invalidatedArea.Width - 20,
invalidatedArea.Top + 2, 18, invalidatedArea.Height - 4), System.Windows.Forms.VisualStyles.ComboBoxState.Pressed);
}
base.OnMouseDown(e);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Rectangle invalidatedArea = this.ClientRectangle;
System.Windows.Forms.ComboBoxRenderer.DrawTextBox(this.CreateGraphics(), new Rectangle(invalidatedArea.Left,
invalidatedArea.Top, invalidatedArea.Width, invalidatedArea.Height), System.Windows.Forms.VisualStyles.ComboBoxState.Normal);
System.Windows.Forms.ComboBoxRenderer.DrawDropDownButton(this.CreateGraphics(), new Rectangle(
invalidatedArea.Left + invalidatedArea.Width - 20,
invalidatedArea.Top+2, 18, invalidatedArea.Height-4), System.Windows.Forms.VisualStyles.ComboBoxState.Normal);
//this.CreateGraphics().DrawString(temp.ToString(), new Font("sum", 12), new SolidBrush(Color.Black), new PointF(1, 1));
}
//弹出窗体关闭时的事件
public void ClosedPopWindow(ToolStripDropDownCloseReason closeReason)
{
#region 控件的动作
if ((ToolStripDropDownCloseReason.Keyboard != closeReason) && (ToolStripDropDownCloseReason.CloseCalled != closeReason))
{
//在combobox单击鼠标时canPop为false
//canPop = !this.RectangleToScreen(this.ClientRectangle).Contains(Cursor.Position);
}
#endregion
}
/// <summary>
/// 用于弹出的窗体的类
/// </summary>
private class PopWindow : ToolStripDropDown
{
#region 委托
//关闭事件委托
public delegate void ClosedPopWindow(ToolStripDropDownCloseReason closeReason);
#endregion
#region 方法
public PopWindow(Control content)
{
control = content;
//create a host that will host the content
host = new ToolStripControlHost(content);
this.Padding = Margin = host.Padding = host.Margin = Padding.Empty;
this.MinimumSize = content.MinimumSize;
content.MinimumSize = content.Size;
MaximumSize = new Size(content.Size.Width + 1, content.Size.Height + 1);
content.MaximumSize = new Size(content.Size.Width + 1, content.Size.Height + 1);
Size = new Size(content.Size.Width + 1, content.Size.Height + 1);
content.Location = Point.Empty;
//add the host to the list
Items.Add(host);
}
#endregion
#region 重载
//窗口关闭时自动调用函数
protected override void OnClosed(ToolStripDropDownClosedEventArgs e)
{
if (null != closedPopWindow)
{
closedPopWindow(e.CloseReason);
}
}
//显示窗口
public new void Show(Point screenLocation)
{
//显示
base.Show(screenLocation);
Focus();
control.Capture = true;
}
//设定焦点
public new bool Focus()
{
return control.Focus();
}
#endregion
#region 变量
//弹出的基窗体
private ToolStripControlHost host;
//具体显示的窗体
Control control;
//关闭事件委托
public ClosedPopWindow closedPopWindow = null;
#endregion
}
}
}
- 一个不完善的可自定义弹出窗体的下拉框
- 一个尚不完善的printf
- 一个可编辑下拉框的例子
- 一个可输入的下拉框插件
- JavaScript 弹出一个可移动的框
- 自定义spinner的下拉弹出窗口样式
- 自定义下拉弹出框
- 【工作笔记】可自定义下拉选项的选择框
- jquery实现下拉框可自定义输入文本的功能
- 自定义可下拉刷新的WebView
- 自定义可下拉上拉的scrollView
- Android 自定义界面的弹出框(可输入数据)
- Android 自定义界面的弹出框(可输入数据)
- Android 自定义界面的弹出框(可输入数据)
- PopupWindow 可自定义的弹出窗
- jquery封装了一个简洁轻巧的可拖动可自定义样式的纯div+css带遮罩层的仿模态弹出框
- div+css实现一个可输入的下拉框
- 分享一个可下拉刷新的ScrollView
- 在视图画矩形并处理鼠标在矩形上的操作
- HDU 1251(搜索题,典型的字典树问题)
- [L-php]PHP功能模块——PHP解析XML,JSON
- 分享成功的项目管理-项目管理对企业和个人的作用-PMP石泉
- 新版中日交流标准日本语初级第五课之基本课文II
- 一个不完善的可自定义弹出窗体的下拉框
- 欧拉函数(模板)
- 最小生成树(Prim模板)
- 开始写技术博客了!
- MinGW如何使用VC编译的DLL??
- Google 菜市场(Android Market)上不去的解决方法
- 《职场菜鸟升职记》-内容与格式
- 删除VS.NET(Visual Studio .NET)最近打开的项目、文件记录、搜索关键字
- tomcat6.0启动不了问题的解决