自定义背景buttonClass
{
border-right: blue 1px solid;
border-top: blue 1px solid;
font-size: 9pt;
background-image: url(button-backgif);
vertical-align: middle;
border-left: blue 1px solid;
cursor: hand;
color: #000000;
border-bottom: blue 1px solid;
font-family: "宋体";
text-align: center;
}
对button加入这个样式单 想作一个带背景的TextBox,给个思路txt
protected override void OnPaint(PaintEventArgs e)
{
Graphics g=textBox1CreateGraphics();
Bitmap bt=new Bitmap(yourFile);
gDrawImage(bt,0,0,textBox1Width,textBox1Height);
}
设置TextBox为Transparent,可以这样:
textBox1BackColor= ColorFromArgb(0, textBox1BackColor);
我大致做了一个,不过还是无法解决在编辑的时候也显示,代码如下:
public class DrawTextBox : SystemWindowsFormsUserControl
{
protected SystemWindowsFormsLabel label;
protected SystemWindowsFormsTextBox textBox;
protected bool editing = false;
/// <summary>
/// Required designer variable
/// </summary>
private SystemComponentModelContainer components = null;
public DrawTextBox()
{
// This call is required by the WindowsForms Form Designer
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}
public Label Label
{
get{return thislabel;}
}
public TextBox TextBox
{
get{return thistextBox;}
}
public bool Editing
{
get{return thisediting;}
set
{
if(thisediting != value)
{
if(!value)
thisEndEditing(value);
else
thisStartEditing();
}
}
}
/// <summary>
/// Clean up any resources being used
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
componentsDispose();
}
}
baseDispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor
/// </summary>
private void InitializeComponent()
{
thislabel = new SystemWindowsFormsLabel();
thistextBox = new SystemWindowsFormsTextBox();
thisSuspendLayout();
//
// label
//
thislabelDock = SystemWindowsFormsDockStyleFill;
thislabelBorderStyle = SystemWindowsFormsBorderStyleFixedSingle;
thislabelName = "label";
thislabelSize = new Size(88, 20);
thislabelTabIndex = 2;
thislabelText = "DrawTextBox1";
thislabelVisible = true;
thislabelMouseUp += new SystemWindowsFormsMouseEventHandler(thisLabel_MouseUp);
//
// textBox
//
thistextBoxBorderStyle = SystemWindowsFormsBorderStyleFixedSingle;
thistextBoxName = "textBox";
thistextBoxTabIndex = 2;
thistextBoxText = "";
thistextBoxVisible = false;
thistextBoxSize = new Size(88, 20);
thistextBoxLocation=new Point(0,0);
thistextBoxLostFocus += new SystemEventHandler(thisTextBox_LostFocus);
//
// DrawTextBox
//
thisControlsAddRange(new SystemWindowsFormsControl[] {
thislabel,
thistextBox});
thisName = "DrawTextBox";
thisResumeLayout(false);
}
#endregion
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(ControlFromHandle(msgHWnd) == thistextBox)
{
if(keyData == KeysEnter)
{
thisEndEditing(true);
return true;
}
else if(keyData == KeysEscape)
{
thisEndEditing(false);
return true;
}
}
return baseProcessCmdKey(ref msg, keyData);
}
private void Label_MouseUp(object sender, SystemWindowsFormsMouseEventArgs e)
{
thisStartEditing();
}
protected virtual void StartEditing()
{
thislabelVisible=false;
thistextBoxModified = false;
thistextBoxVisible = true;
thistextBoxText = thislabelText;
thistextBoxFocus();
thistextBoxSelectionStart = 0;
thistextBoxSelectionLength = 0;
thisediting = true;
}
protected virtual void EndEditing(bool save)
{
if(!thisEditing)
return;
if(save && thistextBoxModified)
{
thislabelText = thistextBoxText;
}
thisediting = false;
thistextBoxText = StringEmpty;
thistextBoxVisible = false;
thislabelVisible=true;
}
private void TextBox_LostFocus(object sender, SystemEventArgs e)
{
thisEndEditing(true);
}
}
使用如下:
DrawTextBox myDrawText=new DrawTextBox();
myDrawTextSize=new Size(88,20);
myDrawTextLabelImage=ImageFromFile(@yourFile,false);
thisControlsAdd(myDrawText);
以上就是关于怎样在后台设置imageButton的背景图全部的内容,包括:怎样在后台设置imageButton的背景图、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)