我想做个winform中类似于属性面板中font中控件 我想做个winform中类似于属性面板中font中控件,也就是说当焦点没在这个控件的时候,看起来像个textbox,当焦点在这个控件的时候,最后面会有个小的button或者向下的箭头! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 LZ你是想要调整字体的效果,还是要个COMBOX下拉单效果?还是想要WORD里直接下拉单选字体的效果? properygridhttp://www.codeproject.com/KB/cpp/DynamicDropDownProperties.aspx 你用自定义控件,在上面放一个textbox和butten,然后用代码获取到鼠标的焦点,当textbox获取到的时候butten显示,否则的话隐藏,然后其他操作你在butten里操作就可以了。不知道对不对,你可以参考一下,我没有实验。 下面的代码基本实现你要的功能,不过这仅仅是个示例。而且只能显示字符串,你参考一下吧思路就是使用了一个UserControl,里面有一个ComboBox和一个Label,当需要编辑时就显示combobox,不需要编辑了就显示label public class ComboBoxControl : UserControl { private Label m_Label; private ComboBox m_ComboBox; private void InitializeComponent() { this.m_ComboBox = new System.Windows.Forms.ComboBox(); this.m_Label = new System.Windows.Forms.Label(); this.SuspendLayout(); // // m_ComboBox // this.m_ComboBox.Dock = System.Windows.Forms.DockStyle.Fill; this.m_ComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.m_ComboBox.FormattingEnabled = true; this.m_ComboBox.Location = new System.Drawing.Point(0, 0); this.m_ComboBox.Name = "m_ComboBox"; this.m_ComboBox.Size = new System.Drawing.Size(150, 21); this.m_ComboBox.TabIndex = 0; this.m_ComboBox.Visible = false; this.m_ComboBox.LostFocus += new System.EventHandler(this.m_ComboBox_LostFocus); this.m_ComboBox.SelectedIndexChanged += new System.EventHandler(this.m_ComboBox_SelectedIndexChanged); // // m_Label // this.m_Label.BackColor = System.Drawing.Color.Transparent; this.m_Label.Dock = System.Windows.Forms.DockStyle.Fill; this.m_Label.Location = new System.Drawing.Point(0, 0); this.m_Label.Name = "m_Label"; this.m_Label.Size = new System.Drawing.Size(150, 21); this.m_Label.TabIndex = 1; this.m_Label.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; this.m_Label.MouseDown += new System.Windows.Forms.MouseEventHandler(this.m_Label_MouseDown); // // ComboBoxControl // this.BackColor = System.Drawing.SystemColors.Window; this.Controls.Add(this.m_Label); this.Controls.Add(this.m_ComboBox); this.Name = "ComboBoxControl"; this.Size = new System.Drawing.Size(150, 21); this.ResumeLayout(false); } public ComboBoxControl() { InitializeComponent(); } protected override void OnGotFocus(EventArgs e) { base.OnGotFocus(e); ChangeInnerControlState(true); } public ComboBox.ObjectCollection Items { get { return m_ComboBox.Items; } } public object SelectedItem { get { return m_ComboBox.SelectedItem; } set { m_ComboBox.SelectedItem = value; } } public int SelectedIndex { get { return m_ComboBox.SelectedIndex; } set { m_ComboBox.SelectedIndex = value; } } private void m_Label_MouseDown(object sender, MouseEventArgs e) { ChangeInnerControlState(true); } void m_ComboBox_LostFocus(object sender, EventArgs e) { ChangeInnerControlState(false); } private void ChangeInnerControlState(bool isGotFocus) { m_ComboBox.Visible = isGotFocus; m_Label.Visible = !isGotFocus; if (isGotFocus) m_ComboBox.Focus(); } private void m_ComboBox_SelectedIndexChanged(object sender, EventArgs e) { m_Label.Text = m_ComboBox.SelectedItem.ToString(); } } “WCF异步通信”,同步问题 关于serialport的ReadLine()方法 如何在一个主线程中结束一个后台线程 C#如何调用ice中间件 WebResponse有时会报timeout异常 窗体嵌入Panel遇到的问题 怎样编写邮件收发系统??急急,谢谢!!! 请问如何想以前VB在在IE嵌入Acitvex控件那样,在IE中嵌入WinForm的程序? 怎样编写一个Web自定义控件,例如一个Button? 知道DataGrid的某一列的列名,如何知道它在DataGrid中是第几列? 如何获得远程IP地址 将时间的分钟数尾数转化成0或者5
http://www.codeproject.com/KB/cpp/DynamicDropDownProperties.aspx
public class ComboBoxControl : UserControl
{
private Label m_Label; private ComboBox m_ComboBox; private void InitializeComponent()
{
this.m_ComboBox = new System.Windows.Forms.ComboBox();
this.m_Label = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// m_ComboBox
//
this.m_ComboBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.m_ComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.m_ComboBox.FormattingEnabled = true;
this.m_ComboBox.Location = new System.Drawing.Point(0, 0);
this.m_ComboBox.Name = "m_ComboBox";
this.m_ComboBox.Size = new System.Drawing.Size(150, 21);
this.m_ComboBox.TabIndex = 0;
this.m_ComboBox.Visible = false;
this.m_ComboBox.LostFocus += new System.EventHandler(this.m_ComboBox_LostFocus);
this.m_ComboBox.SelectedIndexChanged += new System.EventHandler(this.m_ComboBox_SelectedIndexChanged);
//
// m_Label
//
this.m_Label.BackColor = System.Drawing.Color.Transparent;
this.m_Label.Dock = System.Windows.Forms.DockStyle.Fill;
this.m_Label.Location = new System.Drawing.Point(0, 0);
this.m_Label.Name = "m_Label";
this.m_Label.Size = new System.Drawing.Size(150, 21);
this.m_Label.TabIndex = 1;
this.m_Label.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.m_Label.MouseDown += new System.Windows.Forms.MouseEventHandler(this.m_Label_MouseDown);
//
// ComboBoxControl
//
this.BackColor = System.Drawing.SystemColors.Window;
this.Controls.Add(this.m_Label);
this.Controls.Add(this.m_ComboBox);
this.Name = "ComboBoxControl";
this.Size = new System.Drawing.Size(150, 21);
this.ResumeLayout(false); } public ComboBoxControl()
{
InitializeComponent();
} protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
ChangeInnerControlState(true);
} public ComboBox.ObjectCollection Items
{
get { return m_ComboBox.Items; }
} public object SelectedItem
{
get { return m_ComboBox.SelectedItem; }
set { m_ComboBox.SelectedItem = value; }
} public int SelectedIndex
{
get { return m_ComboBox.SelectedIndex; }
set { m_ComboBox.SelectedIndex = value; }
} private void m_Label_MouseDown(object sender, MouseEventArgs e)
{
ChangeInnerControlState(true);
} void m_ComboBox_LostFocus(object sender, EventArgs e)
{
ChangeInnerControlState(false);
} private void ChangeInnerControlState(bool isGotFocus)
{
m_ComboBox.Visible = isGotFocus;
m_Label.Visible = !isGotFocus;
if (isGotFocus)
m_ComboBox.Focus();
} private void m_ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
m_Label.Text = m_ComboBox.SelectedItem.ToString();
}
}