using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.VisualStyles; namespace WindowsApplication1 { class MyLabel { private static int idIndex = 0; string id = ""; /// <summary> /// 对象标识 /// </summary> public string Id { get { return id; } } private StringFormat alignVertically = new StringFormat(); /// <summary> /// 获取或设置文本对齐方式 /// </summary> public StringFormat AlignVertically { get { return alignVertically; } set { alignVertically = value; } } private TextAlign textAlign; /// <summary> /// 获取或设置对象文本位置 /// </summary> [Description("设置对象文本位置"), Browsable(true)] public TextAlign TextAlign { get { return textAlign; } set { if (textAlign != value) { textAlign = value; alignVertically = new StringFormat(); alignVertically.LineAlignment = StringAlignment.Center; switch (textAlign) { case TextAlign.Left: alignVertically.Alignment = StringAlignment.Near; break; case TextAlign.Right: alignVertically.Alignment = StringAlignment.Far; break; case TextAlign.Center: alignVertically.Alignment = StringAlignment.Center; break; default: break; } } } } bool myMouseIsDown = false; /// <summary> /// 当前是否选中 /// </summary> public bool MyMouseIsDown { get { return myMouseIsDown; } set { if (myMouseIsDown != value) { myMouseIsDown = value;
} } } Font font = new Font("宋体", 9); /// <summary> /// 获取或设置对象text属性的字体 /// </summary> [Description("设置对象text属性的字体"), Browsable(true)] public Font Font { get { return font; } set { font = value; } } Color backColor = SystemColors.Control; /// <summary> /// 获取或设置对象背景颜色 /// </summary> [Description("设置对象背景颜色"), Browsable(true)] public Color BackColor { get { return backColor; } set { backColor = value; } } Color foreColor = Color.Black; /// <summary> /// 获取或者设置对象前景颜色 /// </summary> [Description("设置对象前景颜色"), Browsable(true)] public Color ForeColor { get { return foreColor; } set { foreColor = value; } } private string text=""; /// <summary> /// 获取或设置对象的文本内容 /// </summary> public string Text { get { return text; } set { text = value; } }
Rectangle bounds = new Rectangle(0, 0, 110, 20); /// <summary> /// 获取或设置对象相对其容器的大小和位置 /// </summary> [Browsable(false)] public Rectangle Bounds { get { return bounds; } set { if (bounds != value) { bounds = value; } } } bool visible = true; /// <summary> /// 获取或设置一个值,该值指示是否显示该对象 /// </summary> public bool Visible { get { return visible; } set { visible = value; } } Control fatherControl; /// <summary> /// 父控件对象(捕捉键盘鼠标用) /// </summary> public Control FatherControl { get { return fatherControl; } set { fatherControl = value; } } /// <summary> /// 构造方法 /// </summary> public MyLabel(Control control) { idIndex++; id = Hthc.Basic.sysCommon.BuildObjectId(); text = "myLabel" + idIndex.ToString(); fatherControl = control; FatherControl.Paint += new PaintEventHandler(FatherControl_Paint); } /// <summary> /// 主控件重绘时绘制本对象 /// </summary> void FatherControl_Paint(object sender, PaintEventArgs e) { OnPaint(e); }
/// <summary> /// 获得本对象位图 /// </summary> /// <returns>位图</returns> public Bitmap DrawToBitmap(Bitmap image) { Graphics e = Graphics.FromImage(image); Rectangle rect = bounds; bounds = new Rectangle(0, 0, bounds.Width, bounds.Height); DrawMe(e); bounds = rect; return image; } /// <summary> /// 获得本对象位图 /// </summary> /// <returns>位图</returns> public Bitmap DrawToBitmap() { Bitmap image = new Bitmap(bounds.Width, bounds.Height); Graphics e = Graphics.FromImage(image); Rectangle rect = bounds; bounds = new Rectangle(0, 0, bounds.Width, bounds.Height); DrawMe(e); bounds = rect; return image; } /// <summary> /// 对象重绘 /// </summary> public void Invalidate() { OnPaint(new PaintEventArgs(FatherControl.CreateGraphics(),Bounds)); } /// <summary> /// 绘制对象样式 /// </summary> protected virtual void DrawMe(Graphics e) { if (!Visible) return; if (Text != "") e.DrawString(Text, this.Font, new SolidBrush(ForeColor), Bounds, AlignVertically); } /// <summary> /// 绘制方法 /// </summary> protected virtual void OnPaint(PaintEventArgs e) { DrawMe(e.Graphics); } } }
private System.Windows.Forms.HelpProvider helpProvider1;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.RichTextBox richTextBox2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.WebBrowser webBrowser2;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.ProgressBar progressBar2;
private System.Windows.Forms.MonthCalendar monthCalendar2;
private System.Windows.Forms.ListView listView2;
private System.Windows.Forms.LinkLabel linkLabel2;
private System.Windows.Forms.MaskedTextBox maskedTextBox2;
private System.Windows.Forms.HScrollBar hScrollBar2;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox comboBox3;
private System.Windows.Forms.ComboBox comboBox4;
private System.Windows.Forms.CheckedListBox checkedListBox2;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.WebBrowser webBrowser1;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.MonthCalendar monthCalendar1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.LinkLabel linkLabel1;
private System.Windows.Forms.MaskedTextBox maskedTextBox1;
private System.Windows.Forms.HScrollBar hScrollBar1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBox2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.CheckedListBox checkedListBox1;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.RichTextBox richTextBox4;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.WebBrowser webBrowser4;
private System.Windows.Forms.RadioButton radioButton4;
private System.Windows.Forms.ProgressBar progressBar4;
private System.Windows.Forms.MonthCalendar monthCalendar4;
private System.Windows.Forms.ListView listView4;
private System.Windows.Forms.LinkLabel linkLabel4;
private System.Windows.Forms.MaskedTextBox maskedTextBox4;
private System.Windows.Forms.HScrollBar hScrollBar4;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.ComboBox comboBox7;
private System.Windows.Forms.ComboBox comboBox8;
private System.Windows.Forms.CheckedListBox checkedListBox4;
private System.Windows.Forms.CheckBox checkBox4;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.RichTextBox richTextBox3;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.WebBrowser webBrowser3;
private System.Windows.Forms.RadioButton radioButton3;
private System.Windows.Forms.ProgressBar progressBar3;
private System.Windows.Forms.MonthCalendar monthCalendar3;
private System.Windows.Forms.ListView listView3;
private System.Windows.Forms.LinkLabel linkLabel3;
private System.Windows.Forms.MaskedTextBox maskedTextBox3;
private System.Windows.Forms.HScrollBar hScrollBar3;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox comboBox5;
private System.Windows.Forms.ComboBox comboBox6;
private System.Windows.Forms.CheckedListBox checkedListBox3;
private System.Windows.Forms.CheckBox checkBox3;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.CheckBox checkBox14;
private System.Windows.Forms.Button button14;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.CheckBox checkBox13;
private System.Windows.Forms.Button button13;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.CheckBox checkBox12;
private System.Windows.Forms.Button button12;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.CheckBox checkBox11;
private System.Windows.Forms.Button button11;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.CheckBox checkBox10;
private System.Windows.Forms.Button button10;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.CheckBox checkBox9;
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.CheckBox checkBox8;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.CheckBox checkBox7;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.CheckBox checkBox6;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Label label24;
private System.Windows.Forms.CheckBox checkBox23;
private System.Windows.Forms.Button button23;
private System.Windows.Forms.Label label25;
private System.Windows.Forms.Label label26;
private System.Windows.Forms.CheckBox checkBox24;
private System.Windows.Forms.Button button24;
private System.Windows.Forms.Label label27;
private System.Windows.Forms.CheckBox checkBox25;
private System.Windows.Forms.Button button25;
private System.Windows.Forms.Label label28;
private System.Windows.Forms.CheckBox checkBox26;
private System.Windows.Forms.Button button26;
private System.Windows.Forms.Label label29;
private System.Windows.Forms.CheckBox checkBox27;
private System.Windows.Forms.Button button27;
private System.Windows.Forms.Label label30;
private System.Windows.Forms.CheckBox checkBox28;
private System.Windows.Forms.Button button28;
private System.Windows.Forms.Label label31;
private System.Windows.Forms.CheckBox checkBox29;
private System.Windows.Forms.Button button29;
private System.Windows.Forms.Label label32;
private System.Windows.Forms.CheckBox checkBox30;
private System.Windows.Forms.Button button30;
private System.Windows.Forms.WebBrowser webBrowser6;
private System.Windows.Forms.Label label15;
private System.Windows.Forms.CheckBox checkBox15;
private System.Windows.Forms.Button button15;
private System.Windows.Forms.Label label16;
private System.Windows.Forms.Label label17;
private System.Windows.Forms.CheckBox checkBox16;
private System.Windows.Forms.Button button16;
private System.Windows.Forms.Label label18;
private System.Windows.Forms.CheckBox checkBox17;
private System.Windows.Forms.Button button17;
private System.Windows.Forms.Label label19;
private System.Windows.Forms.CheckBox checkBox18;
private System.Windows.Forms.Button button18;
private System.Windows.Forms.Label label20;
private System.Windows.Forms.CheckBox checkBox19;
private System.Windows.Forms.Button button19;
private System.Windows.Forms.Label label21;
private System.Windows.Forms.CheckBox checkBox20;
private System.Windows.Forms.Button button20;
private System.Windows.Forms.Label label22;
private System.Windows.Forms.CheckBox checkBox21;
private System.Windows.Forms.Button button21;
private System.Windows.Forms.Label label23;
private System.Windows.Forms.CheckBox checkBox22;
private System.Windows.Forms.Button button22;
private System.Windows.Forms.WebBrowser webBrowser5;
private System.Windows.Forms.Label label47;
private System.Windows.Forms.CheckBox checkBox47;
private System.Windows.Forms.Button button47;
private System.Windows.Forms.Label label48;
private System.Windows.Forms.CheckBox checkBox48;
private System.Windows.Forms.Button button48;
private System.Windows.Forms.CheckBox checkBox49;
private System.Windows.Forms.Button button49;
private System.Windows.Forms.CheckBox checkBox50;
private System.Windows.Forms.Button button50;
private System.Windows.Forms.Label label49;
private System.Windows.Forms.CheckBox checkBox51;
private System.Windows.Forms.Button button51;
private System.Windows.Forms.Label label50;
private System.Windows.Forms.Label label51;
private System.Windows.Forms.CheckBox checkBox52;
private System.Windows.Forms.Button button52;
private System.Windows.Forms.Label label52;
private System.Windows.Forms.CheckBox checkBox53;
private System.Windows.Forms.Button button53;
private System.Windows.Forms.Label label53;
private System.Windows.Forms.CheckBox checkBox54;
private System.Windows.Forms.Button button54;
private System.Windows.Forms.RadioButton radioButton7;
private System.Windows.Forms.Label label40;
private System.Windows.Forms.CheckBox checkBox39;
private System.Windows.Forms.Button button39;
private System.Windows.Forms.Label label41;
private System.Windows.Forms.CheckBox checkBox40;
private System.Windows.Forms.Button button40;
private System.Windows.Forms.CheckBox checkBox41;
private System.Windows.Forms.Button button41;
private System.Windows.Forms.CheckBox checkBox42;
private System.Windows.Forms.Button button42;
private System.Windows.Forms.Label label42;
private System.Windows.Forms.CheckBox checkBox43;
private System.Windows.Forms.Button button43;
private System.Windows.Forms.Label label43;
private System.Windows.Forms.Label label44;
private System.Windows.Forms.CheckBox checkBox44;
private System.Windows.Forms.Button button44;
private System.Windows.Forms.Label label45;
private System.Windows.Forms.CheckBox checkBox45;
private System.Windows.Forms.Button button45;
private System.Windows.Forms.Label label46;
private System.Windows.Forms.CheckBox checkBox46;
private System.Windows.Forms.Button button46;
private System.Windows.Forms.RadioButton radioButton6;
private System.Windows.Forms.Label label33;
private System.Windows.Forms.CheckBox checkBox31;
private System.Windows.Forms.Button button31;
private System.Windows.Forms.Label label34;
private System.Windows.Forms.CheckBox checkBox32;
private System.Windows.Forms.Button button32;
private System.Windows.Forms.CheckBox checkBox33;
private System.Windows.Forms.Button button33;
private System.Windows.Forms.CheckBox checkBox34;
private System.Windows.Forms.Button button34;
private System.Windows.Forms.Label label35;
private System.Windows.Forms.CheckBox checkBox35;
private System.Windows.Forms.Button button35;
private System.Windows.Forms.Label label36;
private System.Windows.Forms.Label label37;
private System.Windows.Forms.CheckBox checkBox36;
private System.Windows.Forms.Button button36;
private System.Windows.Forms.Label label38;
private System.Windows.Forms.CheckBox checkBox37;
private System.Windows.Forms.Button button37;
private System.Windows.Forms.Label label39;
private System.Windows.Forms.CheckBox checkBox38;
private System.Windows.Forms.Button button38;
private System.Windows.Forms.RadioButton radioButton5;
采用页面切换的方式.
tab1是1.aspx
tab2是2.aspx这样速度会快很多,不妨试试.
“windows切换各个窗体一样做到无延时 既然是各个窗体 那就是各自有各自的线程 根本就是分开的! 你的tab下有许多label和button 你知道一个label 和button 有多少代码吗?占多大内存? 弄清楚这些 自然会有解决方案 每次切换 都会引起 所有控件的重绘 所以控件多了重绘的东西就多了
简单点说就是 每切换一次 都得计算要显示的控件 位置了、绘制点了、然后绘制,还有一些必须执行的控件代码
”
就是不知道该怎么解决说到的这几个问题,我对界面绘制方面的知识比较差,hiddkiller能帮忙再说细一点吗?谢谢了
我也不会 我只知道 一个控件继承下来到能可以拖放到窗体的时候 它的代码量已经很大了~~
现在我正在做的项目 比如象Label 都没有用控件 而是一个class对象 主要功能就是在指定的Rectangle 上绘制一段文字
TextBox 也是自己写的<未继承任何类 object除外> 没用.net 的控件
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace WindowsApplication1
{
class MyLabel
{
private static int idIndex = 0;
string id = "";
/// <summary>
/// 对象标识
/// </summary>
public string Id
{
get { return id; }
}
private StringFormat alignVertically = new StringFormat();
/// <summary>
/// 获取或设置文本对齐方式
/// </summary>
public StringFormat AlignVertically
{
get { return alignVertically; }
set { alignVertically = value; }
}
private TextAlign textAlign;
/// <summary>
/// 获取或设置对象文本位置
/// </summary>
[Description("设置对象文本位置"), Browsable(true)]
public TextAlign TextAlign
{
get { return textAlign; }
set
{
if (textAlign != value)
{
textAlign = value;
alignVertically = new StringFormat();
alignVertically.LineAlignment = StringAlignment.Center;
switch (textAlign)
{
case TextAlign.Left:
alignVertically.Alignment = StringAlignment.Near;
break;
case TextAlign.Right:
alignVertically.Alignment = StringAlignment.Far;
break;
case TextAlign.Center:
alignVertically.Alignment = StringAlignment.Center;
break;
default:
break;
}
}
}
}
bool myMouseIsDown = false;
/// <summary>
/// 当前是否选中
/// </summary>
public bool MyMouseIsDown
{
get { return myMouseIsDown; }
set
{
if (myMouseIsDown != value)
{
myMouseIsDown = value;
}
}
}
Font font = new Font("宋体", 9);
/// <summary>
/// 获取或设置对象text属性的字体
/// </summary>
[Description("设置对象text属性的字体"), Browsable(true)]
public Font Font
{
get { return font; }
set { font = value; }
}
Color backColor = SystemColors.Control;
/// <summary>
/// 获取或设置对象背景颜色
/// </summary>
[Description("设置对象背景颜色"), Browsable(true)]
public Color BackColor
{
get { return backColor; }
set { backColor = value; }
}
Color foreColor = Color.Black;
/// <summary>
/// 获取或者设置对象前景颜色
/// </summary>
[Description("设置对象前景颜色"), Browsable(true)]
public Color ForeColor
{
get { return foreColor; }
set { foreColor = value; }
}
private string text="";
/// <summary>
/// 获取或设置对象的文本内容
/// </summary>
public string Text
{
get { return text; }
set { text = value; }
}
Rectangle bounds = new Rectangle(0, 0, 110, 20);
/// <summary>
/// 获取或设置对象相对其容器的大小和位置
/// </summary>
[Browsable(false)]
public Rectangle Bounds
{
get { return bounds; }
set { if (bounds != value) { bounds = value; } }
}
bool visible = true;
/// <summary>
/// 获取或设置一个值,该值指示是否显示该对象
/// </summary>
public bool Visible
{
get { return visible; }
set { visible = value; }
}
Control fatherControl;
/// <summary>
/// 父控件对象(捕捉键盘鼠标用)
/// </summary>
public Control FatherControl
{
get { return fatherControl; }
set { fatherControl = value; }
}
/// <summary>
/// 构造方法
/// </summary>
public MyLabel(Control control)
{
idIndex++;
id = Hthc.Basic.sysCommon.BuildObjectId();
text = "myLabel" + idIndex.ToString();
fatherControl = control;
FatherControl.Paint += new PaintEventHandler(FatherControl_Paint);
}
/// <summary>
/// 主控件重绘时绘制本对象
/// </summary>
void FatherControl_Paint(object sender, PaintEventArgs e)
{
OnPaint(e);
}
/// <summary>
/// 获得本对象位图
/// </summary>
/// <returns>位图</returns>
public Bitmap DrawToBitmap(Bitmap image)
{
Graphics e = Graphics.FromImage(image);
Rectangle rect = bounds;
bounds = new Rectangle(0, 0, bounds.Width, bounds.Height);
DrawMe(e);
bounds = rect;
return image;
}
/// <summary>
/// 获得本对象位图
/// </summary>
/// <returns>位图</returns>
public Bitmap DrawToBitmap()
{
Bitmap image = new Bitmap(bounds.Width, bounds.Height);
Graphics e = Graphics.FromImage(image);
Rectangle rect = bounds;
bounds = new Rectangle(0, 0, bounds.Width, bounds.Height);
DrawMe(e);
bounds = rect;
return image;
}
/// <summary>
/// 对象重绘
/// </summary>
public void Invalidate()
{
OnPaint(new PaintEventArgs(FatherControl.CreateGraphics(),Bounds));
}
/// <summary>
/// 绘制对象样式
/// </summary>
protected virtual void DrawMe(Graphics e)
{
if (!Visible)
return;
if (Text != "")
e.DrawString(Text, this.Font, new SolidBrush(ForeColor), Bounds, AlignVertically); }
/// <summary>
/// 绘制方法
/// </summary>
protected virtual void OnPaint(PaintEventArgs e)
{
DrawMe(e.Graphics);
} }
}