按钮、菜单的重绘代码

None.gif using  System;
None.gif
using  System.Drawing;
None.gif
using  System.Windows;
None.gif
using  System.Windows.Forms;
None.gif
None.gif
namespace  ControlSet
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif 
/**//// <summary>
InBlock.gif 
/// 自绘按钮
ExpandedSubBlockEnd.gif 
/// </summary>

InBlock.gif public class MyButton : System.Windows.Forms.Button
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  
private bool mouseDown=false;
InBlock.gif  
private bool mouseHover=false;
InBlock.gif  
public MyButton()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   SetStyle(ControlStyles.UserPaint,
true);
InBlock.gif   MouseDown
+=new MouseEventHandler(OnMouseDown);
InBlock.gif   MouseUp
+=new MouseEventHandler(OnMouseUp);
InBlock.gif   MouseEnter
+=new EventHandler(OnMouseEnter);
InBlock.gif   MouseLeave
+=new EventHandler(OnMouseLeave);
InBlock.gif   Height
=23;
InBlock.gif   Width
=75;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
protected override void OnPaint(PaintEventArgs pe)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   pe.Graphics.FillRectangle(
new SolidBrush(Parent.BackColor),
InBlock.gif    pe.ClipRectangle);
InBlock.gif   
if (Enabled == false)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    DrawDisableButton(pe.Graphics);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else if (mouseDown)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    DrawMouseDownButton(pe.Graphics);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else if (mouseHover)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    DrawMouseHoverButton(pe.Graphics);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else if (Focused)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    DrawContainFocusButton(pe.Graphics);
ExpandedSubBlockEnd.gif   }
 
InBlock.gif   
else
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    DrawNormalButton(pe.Graphics);
ExpandedSubBlockEnd.gif   }

InBlock.gif   WriteText(pe.Graphics);
ExpandedSubBlockEnd.gif  }

InBlock.gif  
private void OnMouseDown(object sender,MouseEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   mouseDown
=true;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void OnMouseUp(object sender,MouseEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   mouseDown
=false;
InBlock.gif   PaintEventArgs pe 
= 
InBlock.gif    
new PaintEventArgs(CreateGraphics(),ClientRectangle);
InBlock.gif   OnPaint(pe);
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void OnMouseEnter(object sender,EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   mouseHover
=true;
InBlock.gif   PaintEventArgs pe 
= 
InBlock.gif    
new PaintEventArgs(CreateGraphics(),ClientRectangle);
InBlock.gif   OnPaint(pe);
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void OnMouseLeave(object sender,EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   mouseHover
=false;
InBlock.gif   PaintEventArgs pe 
=
InBlock.gif    
new PaintEventArgs(CreateGraphics(),ClientRectangle);
InBlock.gif   OnPaint(pe);
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void DrawBorder(Graphics g,int state)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
if (state==1)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    Pen p 
= new Pen(SystemColors.ControlLightLight,2);
InBlock.gif    g.DrawLine(p,
1,1,1,Height-2);
InBlock.gif    g.DrawLine(p,
1,1,Width-2,1);
InBlock.gif    g.DrawLine(p,Width
-1,2,Width-1,Height-2);
InBlock.gif    g.DrawLine(p,
2,Height-1,Width-2,Height-1);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else if (state==2)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    Pen p 
= new Pen(Color.Yellow,2);
InBlock.gif    g.DrawLine(p,
1,1,1,Height-2);
InBlock.gif    g.DrawLine(p,
1,1,Width-2,1);
InBlock.gif    g.DrawLine(p,Width
-1,2,Width-1,Height-2);
InBlock.gif    g.DrawLine(p,
2,Height-1,Width-2,Height-1);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else if (state==3)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    Pen p 
= new Pen(SystemColors.ControlDark,2);
InBlock.gif    g.DrawLine(p,
1,1,1,Height-2);
InBlock.gif    g.DrawLine(p,
1,1,Width-2,1);
InBlock.gif    g.DrawLine(p,Width
-1,2,Width-1,Height-2);
InBlock.gif    g.DrawLine(p,
2,Height-1,Width-2,Height-1);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else if (state==4)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    Pen p 
= new Pen(SystemColors.ControlLight,2);
InBlock.gif    g.DrawLine(p,
1,1,1,Height-2);
InBlock.gif    g.DrawLine(p,
1,1,Width-2,1);
InBlock.gif    g.DrawLine(p,Width
-1,2,Width-1,Height-2);
InBlock.gif    g.DrawLine(p,
2,Height-1,Width-2,Height-1);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else if (state==5)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    Pen p 
= new Pen(Color.SkyBlue,2);
InBlock.gif    g.DrawLine(p,
1,1,1,Height-2);
InBlock.gif    g.DrawLine(p,
1,1,Width-2,1);
InBlock.gif    g.DrawLine(p,Width
-1,2,Width-1,Height-2);
InBlock.gif    g.DrawLine(p,
2,Height-1,Width-2,Height-1);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
if (state==4)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    Pen p 
= new Pen(Color.FromArgb(161,161,146),1);
InBlock.gif    g.DrawLine(p,
0,2,0,Height-3);
InBlock.gif    g.DrawLine(p,
2,0,Width-3,0);
InBlock.gif    g.DrawLine(p,Width
-1,2,Width-1,Height-3);
InBlock.gif    g.DrawLine(p,
2,Height-1,Width-3,Height-1);
InBlock.gif    g.DrawLine(p,
0,2,2,0);
InBlock.gif    g.DrawLine(p,
0,Height-3,2,Height-1);
InBlock.gif    g.DrawLine(p,Width
-3,0,Width-1,2);
InBlock.gif    g.DrawLine(p,Width
-3,Height-1,Width-1,Height-3);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    g.DrawLine(Pens.Black,
0,2,0,Height-3);
InBlock.gif    g.DrawLine(Pens.Black,
2,0,Width-3,0);
InBlock.gif    g.DrawLine(Pens.Black,Width
-1,2,Width-1,Height-3);
InBlock.gif    g.DrawLine(Pens.Black,
2,Height-1,Width-3,Height-1);
InBlock.gif    g.DrawLine(Pens.Black,
0,2,2,0);
InBlock.gif    g.DrawLine(Pens.Black,
0,Height-3,2,Height-1);
InBlock.gif    g.DrawLine(Pens.Black,Width
-3,0,Width-1,2);
InBlock.gif    g.DrawLine(Pens.Black,Width
-3,Height-1,
InBlock.gif     Width
-1,Height-3);
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void DrawNormalButton(Graphics g)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DrawBorder(g,
1);
InBlock.gif   PaintBack(g,SystemColors.ControlLightLight);
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void DrawMouseHoverButton(Graphics g)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DrawBorder(g,
2);
InBlock.gif   PaintBack(g,SystemColors.ControlLightLight);
ExpandedSubBlockEnd.gif  }
  
InBlock.gif
InBlock.gif  
private void DrawMouseDownButton(Graphics g)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DrawBorder(g,
3);
InBlock.gif   PaintBack(g,SystemColors.ControlLight);
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void DrawDisableButton(Graphics g)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DrawBorder(g,
4);
InBlock.gif   PaintBack(g,SystemColors.ControlLight);
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void DrawContainFocusButton(Graphics g)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   DrawBorder(g,
5);
InBlock.gif   PaintBack(g,SystemColors.ControlLightLight);
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void PaintBack(Graphics g,Color c)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   g.FillRectangle(
new SolidBrush(c),3,3,
InBlock.gif    Width
-6,Height-6);
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void WriteText(Graphics g)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
int x=0,y=0;
InBlock.gif   Size s 
= g.MeasureString(Text,Font).ToSize();
InBlock.gif   x
=(Width-s.Width)/2;
InBlock.gif   y
=(Height-s.Height)/2;
InBlock.gif   
if (Enabled)
InBlock.gif    g.DrawString(Text,Font,Brushes.Black,x,y);
InBlock.gif   
else
InBlock.gif    g.DrawString(Text,Font,Brushes.Gray,x,y);
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

None.gif
None.gif※※※※※※※※※※※※※※※※
None.gif
None.gif 
None.gif
None.gif菜单:
None.gif
using  System;
None.gif
using  System.Windows;
None.gif
using  System.Drawing;
None.gif
using  System.Windows.Forms;
None.gif
using  System.ComponentModel;
None.gif
using  System.Drawing.Text;
None.gif
using  System.Diagnostics;
None.gif
using  System.Collections;
None.gif
None.gif
namespace  ControlSet
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif 
/**//// <summary>
InBlock.gif 
/// 自绘菜单
ExpandedSubBlockEnd.gif 
/// </summary>

InBlock.gif public class OwnerDrawMenu : MenuItem 
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  
private static Color backcolor;
InBlock.gif  
private static Color barcolor;
InBlock.gif  
private static Color selectioncolor;
InBlock.gif  
private static Color framecolor;
InBlock.gif  
private static int iconSize = SystemInformation.SmallIconSize.Width + 5;
InBlock.gif  
private static int itemHeight;
InBlock.gif  
private string shortcuttext = "";
InBlock.gif  
private Image icon   = null;
InBlock.gif  
private static int BITMAP_SIZE = 16;
InBlock.gif  
private static int STRIPE_WIDTH = iconSize + 5;
InBlock.gif
InBlock.gif  
public OwnerDrawMenu() : base() 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   OwnerDraw 
= true
ExpandedSubBlockEnd.gif  }

InBlock.gif  
InBlock.gif  
private OwnerDrawMenu(string name) : base(name) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   OwnerDraw 
= true
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
public OwnerDrawMenu(string name, EventHandler handler) : base(name, handler) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   OwnerDraw 
= true
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private OwnerDrawMenu(string name, EventHandler handler, Shortcut shortcut) : base(name, handler, shortcut) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   OwnerDraw 
= true;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private OwnerDrawMenu(MenuMerge mergeType, int mergeOrder, Shortcut shortcut, string name, EventHandler onClick, EventHandler onPopup, EventHandler onSelect, OwnerDrawMenu[] items) : base(mergeType, mergeOrder, shortcut, name, onClick, onPopup, onSelect, items) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   OwnerDraw 
= true;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private OwnerDrawMenu(string name, Image img) : this(name) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   OwnerDraw 
= true;
InBlock.gif   icon 
= img;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private OwnerDrawMenu(string name, EventHandler handler, Image img) : this(name, handler) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   OwnerDraw 
= true;
InBlock.gif   icon 
= img;
ExpandedSubBlockEnd.gif  }

InBlock.gif  
InBlock.gif  
private OwnerDrawMenu(string name, EventHandler handler, Shortcut shortcut, Image img) : this(name, handler, shortcut) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   OwnerDraw 
= true;
InBlock.gif   icon 
= img;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
public Image Icon 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
get
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
return icon;
ExpandedSubBlockEnd.gif   }

InBlock.gif   
set
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    icon 
= value;
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private string ShortcutText 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
get 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gifreturn shortcuttext; }
InBlock.gif   
set 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{ shortcuttext = value; }
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
public Color SelectionColor
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
get
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gifreturn selectioncolor; }
InBlock.gif   
set
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{ selectioncolor = value; }
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
public Color BackColor
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
get
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gifreturn backcolor; }
InBlock.gif   
set
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{ backcolor = value; }
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
public Color BarColor
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
get
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gifreturn barcolor; }
InBlock.gif   
set
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{ barcolor = value; }
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
public Color FrameColor
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
get
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gifreturn framecolor; }
InBlock.gif   
set
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{ framecolor = value; }
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
protected override void OnMeasureItem(MeasureItemEventArgs e) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
if (Shortcut != Shortcut.None) 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
string text = "";
InBlock.gif    
int    key  = (int)Shortcut;
InBlock.gif    
int    ch   = key & 0xFF;
InBlock.gif    
if (((int)Keys.Control & key) > 0) text += "Ctrl+";
InBlock.gif    
if (((int)Keys.Shift & key) > 0) text += "Shift+";
InBlock.gif    
if (((int)Keys.Alt & key) > 0) text += "Alt+";
InBlock.gif    
if (ch >= (int)Shortcut.F1 && ch <= (int)Shortcut.F12)
InBlock.gif     text 
+= "F" + (ch - (int)Shortcut.F1 + 1);
InBlock.gif    
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     
if ( Shortcut == Shortcut.Del) 
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif      text 
+= "Del";
ExpandedSubBlockEnd.gif     }

InBlock.gif     
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif      text 
+= (char)ch;
ExpandedSubBlockEnd.gif     }

ExpandedSubBlockEnd.gif    }

InBlock.gif    shortcuttext 
= text;
ExpandedSubBlockEnd.gif   }
 
InBlock.gif   
if (Text == "-"
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    e.ItemHeight 
= 8;
InBlock.gif    e.ItemWidth  
= 4;
InBlock.gif    
return;
ExpandedSubBlockEnd.gif   }

InBlock.gif   
bool topLevel = Parent == Parent.GetMainMenu();
InBlock.gif   
string tempShortcutText = shortcuttext;
InBlock.gif   
if ( topLevel ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    tempShortcutText 
= "";
ExpandedSubBlockEnd.gif   }

InBlock.gif   
int textwidth = (int)(e.Graphics.MeasureString(Text + tempShortcutText, SystemInformation.MenuFont).Width);
InBlock.gif   
int extraHeight = 4;
InBlock.gif   e.ItemHeight  
= SystemInformation.MenuHeight + extraHeight;
InBlock.gif   
if ( topLevel )
InBlock.gif    e.ItemWidth  
= textwidth - 5
InBlock.gif   
else
InBlock.gif    e.ItemWidth   
= Math.Max(160, textwidth + 50);
InBlock.gif   itemHeight 
= e.ItemHeight;
InBlock.gif   
base.OnMeasureItem(e);
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif
protected override void OnDrawItem(DrawItemEventArgs e) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   Graphics g 
= e.Graphics;
InBlock.gif   Rectangle bounds 
= e.Bounds;
InBlock.gif   
bool selected = (e.State & DrawItemState.Selected) > 0;
InBlock.gif   
bool toplevel = (Parent == Parent.GetMainMenu());
InBlock.gif   
bool hasicon  = Icon != null;
InBlock.gif   
bool enabled = Enabled;
InBlock.gif   DrawBackground(g, bounds, e.State, toplevel, hasicon, enabled);
InBlock.gif   
if (hasicon)
InBlock.gif    DrawIcon(g, Icon, bounds, selected, Enabled, Checked);
InBlock.gif   
else
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
if (Checked)
InBlock.gif     DrawCheckmark(g, bounds, selected);
InBlock.gif    
if (RadioCheck)
InBlock.gif     DrawRadioCheckmark(g, bounds, selected);
ExpandedSubBlockEnd.gif   }

InBlock.gif
InBlock.gif   
if (Text == "-"
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{ DrawSeparator(g, bounds); } 
InBlock.gif   
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    DrawMenuText(g, bounds, Text, shortcuttext, Enabled, toplevel, e.State); 
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void DrawRadioCheckmark(Graphics g, Rectangle bounds, bool selected) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
int checkTop = bounds.Top + (itemHeight - BITMAP_SIZE)/2;
InBlock.gif   
int checkLeft = bounds.Left + ( STRIPE_WIDTH - BITMAP_SIZE)/2;
InBlock.gif   ControlPaint.DrawMenuGlyph(g, 
new Rectangle(checkLeft, checkTop, BITMAP_SIZE, BITMAP_SIZE), MenuGlyph.Bullet);
InBlock.gif   g.DrawRectangle(
new Pen(framecolor), checkLeft-1, checkTop-1, BITMAP_SIZE+1, BITMAP_SIZE+1);
ExpandedSubBlockEnd.gif  }

InBlock.gif  
private void DrawCheckmark(Graphics g, Rectangle bounds, bool selected) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
int checkTop = bounds.Top + (itemHeight - BITMAP_SIZE)/2;
InBlock.gif   
int checkLeft = bounds.Left + ( STRIPE_WIDTH - BITMAP_SIZE)/2;
InBlock.gif   ControlPaint.DrawMenuGlyph(g, 
new Rectangle(checkLeft, checkTop, BITMAP_SIZE, BITMAP_SIZE), MenuGlyph.Checkmark);
InBlock.gif   g.DrawRectangle(
new Pen(framecolor), checkLeft-1, checkTop-1, BITMAP_SIZE+1, BITMAP_SIZE+1);
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void DrawIcon(Graphics g, Image icon, Rectangle bounds, bool selected, bool enabled, bool ischecked) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
int iconTop = bounds.Top + (itemHeight - BITMAP_SIZE)/2;
InBlock.gif   
int iconLeft = bounds.Left + (STRIPE_WIDTH - BITMAP_SIZE)/2;
InBlock.gif   
if (enabled) 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
if (selected) 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     ControlPaint.DrawImageDisabled(g, icon, iconLeft 
+ 1, iconTop, Color.Black);
InBlock.gif     g.DrawImage(icon, iconLeft, iconTop
-1);
ExpandedSubBlockEnd.gif    }
 
InBlock.gif    
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     g.DrawImage(icon, iconLeft 
+ 1, iconTop);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }
 
InBlock.gif   
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    ControlPaint.DrawImageDisabled(g, icon, iconLeft 
+ 1, iconTop, SystemColors.HighlightText);
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif 
InBlock.gif  
private void DrawSeparator(Graphics g, Rectangle bounds) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
int y = bounds.Y + bounds.Height / 2;
InBlock.gif   g.DrawLine(
new Pen(SystemColors.ControlDark), bounds.X + iconSize + 7, y, bounds.X + bounds.Width - 2, y);
ExpandedSubBlockEnd.gif  }

InBlock.gif  
InBlock.gif  
private void DrawBackground(Graphics g, Rectangle bounds, DrawItemState state, bool toplevel, bool hasicon, bool enabled) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
bool selected = (state & DrawItemState.Selected) > 0;
InBlock.gif   
if (selected || ((state & DrawItemState.HotLight) > 0)) 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
if (toplevel && selected) 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     bounds.Inflate(
-10);
InBlock.gif     g.FillRectangle(
new SolidBrush(barcolor), bounds);
InBlock.gif     ControlPaint.DrawBorder3D(g, bounds.Left, bounds.Top, bounds.Width, bounds.Height, Border3DStyle.SunkenOuter, Border3DSide.Top 
| Border3DSide.Left | Border3DSide.Right | Border3DSide.Bottom);
ExpandedSubBlockEnd.gif    }
 
InBlock.gif    
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     
if(toplevel)
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif      bounds.Inflate(
-10);
InBlock.gif      g.FillRectangle(
new SolidBrush(barcolor), bounds);
InBlock.gif      ControlPaint.DrawBorder3D(g, bounds.Left, bounds.Top, bounds.Width, bounds.Height, Border3DStyle.RaisedInner, Border3DSide.Top 
| Border3DSide.Left | Border3DSide.Right | Border3DSide.Bottom);
ExpandedSubBlockEnd.gif     }

InBlock.gif     
else
InBlock.gif      
if (enabled ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif      g.FillRectangle(
new SolidBrush(selectioncolor), bounds);
InBlock.gif      g.DrawRectangle(
new Pen(framecolor), bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1);
ExpandedSubBlockEnd.gif     }

InBlock.gif     
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif     
dot.gif{
InBlock.gif      g.FillRectangle(
new SolidBrush(barcolor), bounds);
InBlock.gif      bounds.X 
+= STRIPE_WIDTH;
InBlock.gif      bounds.Width 
-= STRIPE_WIDTH;
InBlock.gif      g.FillRectangle(
new SolidBrush(backcolor), bounds);
ExpandedSubBlockEnd.gif     }

ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }
 
InBlock.gif   
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
if (!toplevel) 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     g.FillRectangle(
new SolidBrush(barcolor), bounds);
InBlock.gif     bounds.X 
+= STRIPE_WIDTH;
InBlock.gif     bounds.Width 
-= STRIPE_WIDTH;
InBlock.gif     g.FillRectangle(
new SolidBrush(backcolor), bounds);
ExpandedSubBlockEnd.gif    }
 
InBlock.gif    
else 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     g.FillRectangle(SystemBrushes.Control, bounds);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
private void DrawMenuText(Graphics g, Rectangle bounds, string text, string shortcut, bool enabled, bool toplevel, DrawItemState state ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   StringFormat stringformat 
= new StringFormat();
InBlock.gif   stringformat.HotkeyPrefix 
= ((state & DrawItemState.NoAccelerator) > 0? HotkeyPrefix.Hide : HotkeyPrefix.Show;
InBlock.gif   
if ( toplevel ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    
int index = text.IndexOf("&");
InBlock.gif    
if ( index != -1 ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif     text 
= text.Remove(index,1);
ExpandedSubBlockEnd.gif    }

ExpandedSubBlockEnd.gif   }

InBlock.gif   
int textwidth = (int)(g.MeasureString(text, SystemInformation.MenuFont).Width);
InBlock.gif   
int x = toplevel ? bounds.Left + (bounds.Width - textwidth) / 2: bounds.Left + iconSize + 10;
InBlock.gif   
int topGap = 7;
InBlock.gif   
if ( toplevel ) topGap = 2;
InBlock.gif   
int y = bounds.Top + topGap;
InBlock.gif   Brush brush 
= null;
InBlock.gif   
if (!enabled)
InBlock.gif    brush 
= new SolidBrush(SystemColors.GrayText);
InBlock.gif   
else 
InBlock.gif    brush 
= new SolidBrush(SystemColors.MenuText);
InBlock.gif   g.DrawString(text, SystemInformation.MenuFont, brush, x, y, stringformat);
InBlock.gif   
if ( !toplevel ) 
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    stringformat.FormatFlags 
|= StringFormatFlags.DirectionRightToLeft;
InBlock.gif    g.DrawString(shortcut, SystemInformation.MenuFont, brush, bounds.Width 
- 10 , bounds.Top + topGap, stringformat);
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

None.gif
None.gif※※※※※※※※※※※※※※※※※※
None.gif
None.gif用友单据的面板(Panel)的代码:
None.gif
using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Drawing;
None.gif
using  System.Data;
None.gif
using  System.Windows.Forms;
None.gif
None.gif
namespace  ControlSet
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif 
/**//// <summary>
InBlock.gif 
/// 单据Panel
ExpandedSubBlockEnd.gif 
/// </summary>

InBlock.gif public class SheetPanel : System.Windows.Forms.Panel
ExpandedSubBlockStart.gifContractedSubBlock.gif 
dot.gif{
InBlock.gif  
public SheetPanel()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
this.BorderStyle=BorderStyle.None;
ExpandedSubBlockEnd.gif  }

InBlock.gif
InBlock.gif  
protected override void OnPaint(PaintEventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   Graphics g
=e.Graphics;
InBlock.gif   SolidBrush backbrush 
= new SolidBrush(this.Parent.BackColor);
InBlock.gif   g.FillRectangle(backbrush,
0,0,this.Width,this.Height);
InBlock.gif   Pen pen 
= new Pen(Color.Black,1);
InBlock.gif   g.DrawLine(pen,
this.Width-4,4,this.Width-2,4);
InBlock.gif   g.DrawLine(pen,
4,this.Height-2,4,this.Height-4);
InBlock.gif   g.DrawLine(pen,
this.Width-2,4,this.Width-2,this.Height-2);
InBlock.gif   g.DrawLine(pen,
4,this.Height-2,this.Width-2,this.Height-2);
InBlock.gif   g.DrawRectangle(pen,
2,2,this.Width-6,this.Height-6);
InBlock.gif   backbrush.Color
=this.BackColor;
InBlock.gif   g.FillRectangle(backbrush,
0,0,this.Width-6,this.Height-6);
InBlock.gif   g.DrawRectangle(pen,
0,0,this.Width-6,this.Height-6);
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif }

ExpandedBlockEnd.gif}

None.gif
None.gif
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值