2024年2月9日发(作者:)

DotNet第三方控件使用笔记

0、

1) ButtonX控件

可实现如下效果:

在ButtonX上,是否显示“图像,取决于“images“属性

2)在“buttomItem“控件中,是否“只是显示图像”,”只是文本”,还是“图像和文本都显示”,取决于

1、 BalloonTio控件(气泡提示)

(1) 使用效果

1) 效果一:在鼠标在控件上面停留时,出现提示信息,如下图:

2) 效果二:当控件获得焦点时,也出现如上图一样的信息。

(2) 实现上述两种效果的途径

1) 将BalloonTip控件的“ShowBalloonOnFacus”属性设置为“False”即可实现,效果一。

2) 将“ShowBalloonOnFacus”属性设置为“True”,即可实现效果二。

(3) 设置BalloonTip显示的内容:

在欲设置该属性的控件的“BalloonTioOnFocus上的BalloonCaption”和“BalloonTioOnHover上的BalloonCaption”属性中,分别设置这两种效果的“标题”属性;

在“BalloonTioOnFocus上的BalloonText”和在“BalloonTioOnHover上的BalloonText”属性中,分别设置这两种效果的“显示内容”的属性。

(4) 属性“AlerAnimation”设置“BalloonTip”出现的效果,

(5) “BalloonTip”除了出现在该控件附近,还可以出现在屏幕的右下角,示例程序如下:

private AlertCustom m_AlertOnLoad=null;

m_AlertOnLoad=new AlertCustom();

Rectangle r=kingArea(this);

m_on=new

Point(-m_,-m_);

m_ose=true;

m_oseTimeOut=15;

m_nimation=ToTop;

m_nimationDuration=300;

m_(false);//false::指示该控件是否需要获得焦点才出现“BalloonTip”

序如下:

(6)“BalloonTip”除了可以通过“添加控件”的方式使用,也可以通过编程的方式使用,示例程 n b=new n();

=;

nImage=() as Image;

nText="Balloon Status Information";

="Balloons are now enabled for Balloon Tip Test area. Hover mouse over

the area and set the focus to any control.";

nimation=ottom;

size();

ose=true;

oseTimeOut=4;

=this;//指示父控件

(button2,false);//button2::指示在那个控件附近出现“BalloonTip”

(7)还可以对“BalloonTip”出现时的效果进行程序控制,如下:

// BalloonTriggerControl property returns control that invoked balloon

// BalloonTriggerControl属性返回触发“BalloonTip”的控件

4);

//Offset属性将点p进行平移

on=p;

}

if(nTriggerControl==groupBox1)

{

// BalloonControl is already prepared Balloon control that is just about to be displayed

// Setting BalloonControl to null will cancel balloon display

Point p=osition;

// Adjust cursor position so cursor is below tip

(-set,gth+(8)与之类似的是DotNetToolTip所有控件都有的“ToolTip”属性,也可以是控件在鼠标划过时出现类

似的东西,如下图

2、 DotNetBarManager控件与Bar控件的使用

示例效果如下图:

(1) DotNetBarManager控件

----将该控件添加到工程后,将给Bar控件提供了“停靠点(DockSite)”,可以实现是工具栏在窗体的“上、下、左、右“摆放。

可以通过程序实现,也可以通过“属性页“的”Dock“属性进行设置。

de = ;

(2) DotNetBarManager控件,通过右键菜单

可以轻松实现如下图所示的布局。

通过拖动也可以轻易的实现如下视图的布局

与上图相应的代码:

// Create new document and add it to existing bar

ntainerItem

ntainerItem();

="Custom Document";

// Add control to it

TextBox t=new TextBox();

ze=false;

ine=true;

=;

// PanelDockContainer will be used to host any controls. It provides automatic focus management

so focused

// document tab appears bold

dockItem=new

ockContainer

ockContainer();

= ;

(t);

l=panel;

(dockItem);

if(!e)

e=true;

else

Layout();

panel = new

// Optimize display by disabling layout for all dock sites

dLayout=true;

try

{

foreach( bar in )

{

if(de==nt)

{

foreach(ntainerItem dock in )

e=true;

}

if(!e)

e=true;

}

}

finally

{

dLayout=false;

}

(2×)下面的代码通过编程的方式实现如下图所示的功能

private void Form1_Load(object sender, rgs e)

{

bChange+=new

bChangeEventHandler(bChanged);

CreateBottomBarAutoHide();

CreateLeftDockedBars();

}

private void DockTabChanged(object sender, DockTabChangeEventArgs e)

{

// Sync caption of the bar with the currently selected dock tab

Bar bar=sender as Bar;

if(bar==null || ==null)

return;

=;

}

private void CreateBottomBarAutoHide()

{

Bar bar=new Bar("Bottom Bar in auto-hide state");

="bottomBar";

Type=ntainer; // Dock Container Layout needed for dockable windows

h=true; // Dockable windows stretch to fill container

deAnimationTime=0; // Some controls do not support animation so turn it off

ndleStyle=n; // Dockable Windows have captions

(bar); // DotNetBar needs to be aware of the bar so it can manage it's

docking etc.

// Create hosted controls

DockContainerItem dockItem=new DockContainerItem("bottomDockItem1","First dock item");

(dockItem);

// Create control that we want to host on dockable window

UserControl1 dockedControl=new UserControl1();

=+" - "+;

lor=;

l=dockedControl; // Specify that control is hosted on the dock container

=128; // Specify the height of the dockable container and at the same time control

// Create second dock container and add it to the bar

dockItem=new DockContainerItem("bottomDockItem2","Second dock item");

(dockItem);

dockedControl=new UserControl1();

=+" - "+;

lor=rine;

l=dockedControl; // Specify that control is hosted on the dock container

// Dock bar to bottom dock site

umentUIManager().Dock(bar);

=128; // Specify the height of the dockable container and at the same time control

Layout(); // Apply

de=true; // Place bar in auto-hide mode. Bar needs to be docked before it can be places

in auto-hide mode

}

private void CreateLeftDockedBars()

{

// Dock first two bars side by side and dock third bar next

Bar bar=new Bar("Bar1");

="leftBar1";

Type=ntainer; // Dock Container Layout needed for dockable windows

h=true; // Dockable windows stretch to fill container

deAnimationTime=0; // Some controls do not support animation so turn it off

ndleStyle=n; // Dockable Windows have captions

e=true;

// Create DockContainerItem for the bar. The item should be added before the bar is docked.

DockContainerItem dockItem=new DockContainerItem("leftDockItem1","Top Left Dock Container");

(dockItem);

// Create control that is hosted on dock container

UserControl1 dockedControl=new UserControl1();

=+" - "+;

lor=;

l=dockedControl; // Specify that control is hosted on the dock container

(bar); // DotNetBar needs to be aware of the bar so it can manage it's

docking etc.

umentUIManager().Dock(bar); //Performs actual docking of

the Bar to the specified dock site

=128; // Specify Width of dock container item after it is docked

// Create second bar and dock it below the first bar but still on the same line

Bar bar2=new Bar("Bar2");

="leftBar2";

Type=ntainer; // Dock Container Layout needed for dockable

windows

deAnimationTime=0; // Some controls do not support animation so turn it off

h=true; // Dockable windows stretch to fill container

e=true;

ndleStyle=n; // Dockable Windows have captions

// Add new Dock Container to the bar, should be done before adding the bar so size can be calculated

properly

dockItem=new DockContainerItem("leftDockItem2","Bottom Left Dock Container");

(dockItem);

// Create control that is hosted on dock container

dockedControl=new UserControl1();

=+" - "+;

lor=er;

l=dockedControl; // Specify that control is hosted on the dock container

(bar2); // DotNetBar needs to be aware of the bar so it can manage it's

docking etc.

umentUIManager().Dock(bar, bar2, ); //

Dock new bar2 below the bar that we created previously

// Create third bar that is docked next to the first and second

// i.e. on the line 1

bar=new Bar("Bar3");

="leftBar3";

Type=ntainer; // Dock Container Layout needed for dockable windows

deAnimationTime=0; // Some controls do not support animation so turn it off

h=true; // Dockable windows stretch to fill container

e=true;

ndleStyle=n; // Dockable Windows have captions

dockItem=new DockContainerItem("leftDockItem3","Left Dock Container line 1");

(dockItem);

// Create control that is hosted on dock container

dockedControl=new UserControl1();

=+" - "+;

lor=hiffon;

l=dockedControl; // Specify that control is hosted on the dock container

(bar); // DotNetBar needs to be aware of the bar so it can manage it's

docking etc.

umentUIManager().Dock(bar);

// Setting the width of the dock site will also scale the bars docked inside,

// however the size should be large enough to accomodate all bars including the constraints like

MinimumSize etc.

= 150;

}

BaseItem::Defines the base class for items that are used by DotNetBar

示例:

BaseItem item = sender as BaseItem;

(3) 添加“菜单项“也可以通过两种方式实现

1)“可视化“的方式

在“设计器“里可以通过”右键“来实现;

2)程序的方法

private void CreateBar()

// Add Items to it

ButtonItem item, fileItem;

// New添加新建

item=new ButtonItem("bNew");

ndex=0;

//向Bar内添加项

{

// Create a new Bar

Bar bar=new Bar("Standard");

e=true;

=2003;

ndleStyle=Flat;

emsDock=true;

emsFloat=false;

//创建Bar

-----------------------------------------------------

// = [0];

-------------------------------------------------

// Open

="&New";

();

ry="Standard";

(item);

// This will create Category Entry m_(());

item=new ButtonItem("bOpen");

ndex=1;

="&Open";

();

ry="Standard";

(item);

m_(());

// Add Sub items to the Open, something like recently

fileItem=new ButtonItem("file1");

="&1. ";

(fileItem);

fileItem=new ButtonItem("file2");

="&2. ";

(fileItem);

fileItem=new ButtonItem("file3");

="&3. ";

(fileItem);

fileItem=new ButtonItem("file4");

="&4. ";

(fileItem);

fileItem=new ButtonItem("file5");

="&5. ";

(fileItem);

// Close

item=new ButtonItem("bClose");

ndex=2;

="&Close";

();

ry="Standard";

(item);

m_(());

// Save

item=new ButtonItem("bSave");

ndex=3;

="&Save";

();

ry="Standard";

(item);

m_(());

// Print Preview

item=new ButtonItem("bPrintPreview");

}

ndex=6;

="Print Pre&view";

ry="Standard";

roup=true;

(item);

m_(());

// Print

item=new ButtonItem("bPrint");

ndex=5;

="&Print";

ry="Standard";

();

(item);

m_(());

// E-Mail

item=new ButtonItem("bEmail");

ndex=4;

="&Email";

ry="Standard";

roup=true;

(item);

m_(());

// Customize Item添加“添加/删除“按钮

CustomizeItem citem=new CustomizeItem();

(citem);

// Since we will be using ImageList bar have to be added to the DotNetBar Manager

m_(bar);

de=;

//将Bar加入DotNetBar Manager

(4) 为所有选项添加“事件“

this.m_ick += new andler(mClick);

-----------------------------------------------------------------

private void BarItemClick(object sender, EventArgs e)

{

BaseItem item = sender as BaseItem;

if (item == null || == "" || Item)

return;

("Item '" + + "' clicked");

}

(4)

//设置窗体的大小

AutoScaleBaseSize 属性的值在窗体显示时使用,用来计算该窗体的缩放因子。窗体将自动缩放基大小(用作与系统的字体大小进行比较的基准),以确定使用自动缩放时窗体的缩放量。如果要确定根据特定字体窗体将自动缩放到的大小,请使用

GetAutoScaleSize 方法。

示例:

aleBaseSize = new (11, 17);

该属性将按着Size(a,b)内a与b的比例大小自动调整窗口大小,但是值得注意的是:a与b的绝对值越大,窗口越小。

//设置工作区域的大小

Size = new (351, 207);//

(5)ImageList组件

1)、概述

ImageList组件就是一个图像列表。一般情况下,这个属性用于存储一个图像集合,这些图像用作工具栏图标或TreeView控件上的图标。许多控件都包含ImageList属性。这个属性一般和ImageIndex属性一起使用。ImageList属性设置为ImageList组件的一个实例,ImageIndex属性设置为ImageList中应在控件中显示的图像的索引。使用属性的Add方法可以把图像添加到ImageList组件中。Images属性返回一个ImageCollection。

两个最常用的属性是ImageSize和ColorDepth。ImageSize使用Size结构作为其值。其默认值是16×16,但可以取1~256之间的任意值。ColorDepth使用ColorDepth枚举作为其值。颜色深度值可以从4位~32位。在.NET Framework 1.1中,默认是8Bit。

2)、示例

private ist imageList1;

tream =

((istStreamer)(ect("tream")));

arentColor = arent;

//下面加几个Image

Name(0, "");

Name(1, "address ");

Name(2, "adjust ");

//把imageList1赋给treeView1

ndex = 0;

ist = ist1;

on = new (3, 3);

= "treeView1";

edImageIndex = 0;

= new (579, 450);

ex = 0;

//以上code在Designer完成

//在添加TreeNode的时候, 把Image加上

//未选中时, 这个node显示imageList1中的"", 选中后显示"address

"

TreeNode node = new TreeNode("TreeNodeName", 0, 1);

(node);

All();

3)、讨论

#).ImageList里面的图片的颜色

##)ImageList里面的图片的大小

引起ImageList里面图片颜色失真的原因是在Design-Time就在中往ImageList里面添加了Images。

当用户一边在“Image Collection Editor”对话框里面添加图片,一边就已经把这些图片装载到resource文件里面了。这样,以后程序运行时就只需要访问resource文件就可以载入所有图片而不需要依赖原始的图片文件。

但是问题在于从结果看,当在Design-Time往resource文件里面添加图片时并没有使用用户指定的ColorDepth(例如Depth32Bit),而用了epth的默认值(Depth8Bit)。这样,等程序运行时,即使epth指定了Depth32Bit也无济于事,因为原始的素材本身只有8bit的颜色。这基本上就是waki的问题的原因。

因此,解决方案是:不在Design-Time用往ImageList里面添加图片,而是在程序运行时先指定32Bit的ColorDepth,然后再添加图片,如以下例子代码:

epth=32Bit;

(le(@"C:"));

(le(@"C:Inetpubwwwrootimagesinit_"));

(le(@"C:"));

(le(@"C:"));

这里需要注意的是,必须先指定ColorDepth,然后再添加图片。因为对ColorDepth赋值会清空所有图片。BTW,epth的默认值是Depth8Bit,而非文档上所述Depth4Bit。这一点很容易可以通过写一段例子代码来验证,也可以通过很多Decompiler来查看ImageList的构造函数的实现来验证。

的确,通过[i]获得图片的大小都是统一的,都等于ize。这个问题的原因在于ImageList在返回Images[i]的过程中并没有返回原始的图片,而是按照ize创建了一个新的Bitmap,并把原始图片的内容重新绘制上去以后再返回给用户。关于这一点,可以用一些Decompiler工具如或者Anakrino通过察看私有函数map(int index)

来验证。我想现在paulluo0739应该能够理解为什么ImageList里面的图片都是一样大的了。

ImageSize同ColorDepth类似,也不宜在运行时改动,一旦重新赋值,就会清空所有的图片。因此,如果程序运行时需要某一图片的不同大小的版本,可以考虑使用多个不同ImageSize的ImageList。

(6)关于ImageList组件的用法还存在问题

3、控件BubbleBar的使用

(1)使用效果

(2)其实使用很简单,只有将BubbleBar控件拖到窗体上,然后,就可以添加“Tab“和”Button“了。

(3)一些有用的语句

private void bubbleButton_Click(object sender, ventArgs e)

{

Button button=sender as Button;

=+", "+pText;

}

private void checkBox2_CheckedChanged(object sender, rgs e)

{

}

if(d)

BackgroundStretch=true;

else

// Apply UI changes and refresh

Layout();

h();

BackgroundStretch=false;

//刷新

private void numericUpDown1_ValueChanged(object sender, rgs e)

{

// It is best that images assigned to the control always match this size for best appearance

}

izeNormal=new

Layout();

h();

Size((int),(int));

4、控件DataGridViewX与控件Color Picker的使用

(1)

1)控件DataGridView与DataGridView的基本用法类似

2)DataGridView有自动按列排序的功能

3)

4)edRows[0].Cells[0].ng()

# (2)DataGridView的示例代码

#region 设置DataGridView的显示格式

zeColumnsMode =

;

nerateColumns

= false;

serToAddRows = false;

serToResizeColumns = true;

//////////////////////////////////////////////////////

TabControlPanel tcp;

foreach (Control c in ls)

if (c is TabControlPanel)

{

tcp = (TabControlPanel)c;

= gb(227, 239, 255);

= gb(175, 210, 255);

foreach (Control ctrl in ls)

{

if (ctrl is idViewX)

{

idViewX dgv =

(idViewX)ctrl;

nerateColumns = false;

oundColor = gb(227, 239, 255);

serToAddRows = false;

serToDeleteRows = false;

//ze = false;

zeColumnsMode =

;

zeRowsMode =

ls;

serToResizeColumns = true;

//dersWidth = 900;

elect = false;

ly = true;

dersVisible = false;

Bars = ;

ionMode =

wSelect;

}

}

}

();

();

();

();

();

();

();

("HID", "硬件ID号");

//

("HType", "硬件类型");

("HDetails", "硬件信息");

("MID", "所属机器ID号");

("IP", "所属机器的IP地址");

foreach (DataGridViewColumn col in s)

opertyName = ;

("MID", "机器ID");

("MName", "机器名");

("UID", "用户ID");

s["UID"].Visible = false;

("UName", "用户名");

("IP", "IP地址");

("DeptID", "DeptID");

s["DeptID"].Visible = false;

("Department", "所属部门");

foreach (DataGridViewColumn col in s)

opertyName = ;

urce = Machine( , );

////怎样获得鼠标右击处的行

tInfo hittestinfo = t(e.X, e.Y);

[ex].Selected = true;

(2) 控件Color Picker(colorPickerDropDown1)

——使用效果:

1)单击相应的按钮,工作区(整体)的颜色发生变化

2)随着鼠标在各种颜色上的移动,工作区(整体)的颜色随着变

3)还可以选择“More Colors”进一步改变工作区的颜色

4)下面是相应的代码

private bool m_ColorSelected = false;

private eOffice2007ColorScheme m_BaseColorScheme = ;

//预览,随着鼠标在各种颜色上的移动,工作区(整体)的颜色随着变

private void colorPickerDropDown1_ColorPreview(object sender, ColorPreviewEventArgs e)

{

Office2007ColorTable(m_BaseColorScheme, );

}

//在colorPickerDropDown1上选择颜色后,工作区(整体)的颜色随着变

private void colorPickerDropDown1_ExpandChange(object sender, EventArgs e)

//扩展区域弹出后,所激发的事件,

{

if (ed)

{//刚弹出,则初始化一个颜色值

// Remember the starting color scheme to apply if no color is selected during live-preview

m_ColorSelected = false;

m_BaseColorScheme =

((Office2007Renderer)er).lColorScheme;

}

Else//否则,是“隐去”

{

if (!m_ColorSelected)

{

Office2007ColorTable(m_BaseColorScheme);

}

}

}

//选择颜色后,发生的事件

private void colorPickerDropDown1_SelectedColorChanged(object sender, EventArgs e)

{

m_ColorSelected = true; // Indicate that color was selected for buttonStyleCustom_ExpandChange

method

Office2007ColorTable(m_BaseColorScheme,

edColor);

}

5)说明

×)初始化一个颜色值

m_BaseColorScheme =

((Office2007Renderer)er).lColorScheme;

×)改变颜色值

Office2007ColorTable(m_BaseColorScheme,

edColor);

×)应用颜色值

Office2007ColorTable(m_BaseColorScheme);

6) 工作区的控件的颜色有可能不同时变化

-------原因:是各个控件的“Style”和“ColorSchemeStyle”采用的风格不统一

------解决办法:都采用一种风格,如”Office2007”即可

7)

5、控件SideBar的使用

(1)功能:

可实现如下图似的的分组:

(2)实现方式:

1)右键——>“Add Panel”,进行“分组”

2)对每一个组进行设置

3)右键,对每一个组,添加控件

(3)arColorScheme

--------该控件的颜色策略

scheme=(arColorScheme)(typeof(arColorScheme),sSel,false);

inedColorScheme=scheme;

private void sideBar1_ItemClick(object sender, rgs e)

{

em item=sender as em;

="ItemClick: "+ +" ("++")n"+;

}

(4) Enum枚举类

1)erlyingType 方法

--返回指定枚举的基础类型。

- public static Type GetUnderlyingType(Type enumType)

参数enumType

类型:枚举类型。

返回值类型:

enumType 的基础

Type。

--示例

static object GetAsUnderlyingType(Enum enval)

{

Type entype = e();

Type undertype = erlyingType(entype);

return Type( enval, undertype );

}

2)e

方法

--在指定枚举中检索具有指定值的常数的名称。

——public static string GetName( Type enumType, Object value)

——参数

enumType

类型:

枚举类型。

value

类型:

特定枚举常数的值(根据其基础类型)。

返回值

类型:

一个字符串,该字符串包含

enumType 的枚举常数的名称,该常数的值为

value;或者,如果没有找到这样的常数,则为 nullNothingnullptrnull 引用(在

Visual Basic 中为 Nothing)。

——示例程序

using System;

public class GetNameTest

{

enum Colors { Red, Green, Blue, Yellow };

enum Styles { Plaid, Striped, Tartan, Corduroy };

public static void Main()

{

ine("The 4th value of the Colors Enum is {0}", e(typeof(Colors),

3));

ine("The 4th value of the Styles Enum is {0}", e(typeof(Styles),

3));

}

}

4) es 方法

——检索指定枚举中常数名称的数组。

——public static string[] GetNames( Type enumType)

——参数

enumType

类型:System..::.Type

枚举类型。

返回值

类型:array<>[]()[]

enumType 的常数名称的字符串数组。

——示例程序

using System;

public class GetNamesTest {

enum Colors { Red, Green, Blue, Yellow };

enum Styles { Plaid, Striped, Tartan, Corduroy };

public static void Main()

{

ine("The values of the Colors Enum are:");

foreach(string s in es(typeof(Colors)))

ine(s);

ine();

ine("The values of the Styles Enum are:");

foreach(string s in es(typeof(Styles)))

ine(s);

}

}

5) ues

方法

——检索指定枚举中常数值的数组。

————public static Array GetValues( Type enumType)

————参数

enumType

类型:

枚举类型。

————返回值

类型:

enumType 的常数值的 Array。该数组的元素按枚举常数的二进制值排序。

——示例程序

using System;

public class GetValuesTest {

enum Colors { Red, Green, Blue, Yellow };

enum Styles { Plaid = 0, Striped = 23, Tartan = 65, Corduroy = 78 };

public static void Main()

{

ine("The values of the Colors Enum are:");

foreach(int i in ues(typeof(Colors)))

ine(i);

ine();

ine("The values of the Styles Enum are:");

foreach(int i in ues(typeof(Styles)))

ine(i);

}

}

// The example produces the following output:

// The values of the Colors Enum are:

// 0

// 1

// 2

// 3

//

// The values of the Styles Enum are:

// 0

// 23

// 65

// 78

6) Enum..::.Parse

方法

——将一个或多个枚举常数的名称或数字值的字符串表示转换成等效的枚举对象。

———

名称

Parse(Type,

String)

说明

将一个或多个枚举常数的名称或数字值的字符串表示转换成等效的枚举对象。

String包含要转换的值或名称的字符串。

备注:value

参数中包含一个值、一个已命名常数或由逗号 (,)

分隔的已命名常数列表。在 value

中的每个值、名称或逗号的前面或后面都可以有一个或多个空格。如果 value

是一个列表,则返回值是各指定名称通过按位“或”运算结合而成的值。

示例:

[FlagsAttribute]

enum Colors

{ Red = 1, Green = 2, Blue = 4, Yellow = 8 };

ine("The entries of the Colors Enum are:");

foreach (string colorName in es(typeof(Colors)))

{

ine(

"{0}={1}", colorName ,

32((typeof(Colors), colorName))

);

}

ine();

Colors myOrange = (Colors)(typeof(Colors), "Red, Yel

low");

ine("The myOrange value {1} has the combined entries of {0}",

myOrange, 64(myOrange));

将一个或多个枚举常数的名称或数字值的字符串表示转换成等String, Boolean)

效的枚举对象。一个参数指定该操作是否区分大小写。

Parse(Type,

Boolean参数指定该操作是否区分大小写

7)

示例:

×)es(typeof(arColorScheme))

×)(arColorScheme)(typeof(arColorScheme),sSel,false)

5、Money Style

1)下述语句实现了如下图的功能

// File

menu=new ButtonItem("mFile","&File");

(menu);

// New

menuItem=new ButtonItem("mNew","New");

(menuItem);

// Open

menuItem=new ButtonItem("mOpen","&Open");

();

(menuItem);

// Password manager

menuItem=new ButtonItem("mPasswordManager","Password Manager");

roup=true;//在该按钮前加一条线

(menuItem);

// Backup

menuItem=new ButtonItem("mBackup","&");

roup=true;

(menuItem);

// Restore

menuItem=new ButtonItem("mRestore","&");

(menuItem);

// Archive

menuItem=new ButtonItem("mArchive","&");

(menuItem);

// Exit

menuItem=new ButtonItem("mExit","E&xit");

roup=true;

(menuItem);

// Must add bar to the bars collection so DotNetBarManager is aware of it

//将新建的 Bar 添加到 dotNetBarManager1,

(bar);

// After manager is aware of the bar, we can dock it on appropriate side

de=;

//然后,设置摆放位置

2)

// Standard Toolbar

bar=new Bar("Standard");

// It is important that styles match otherwise style will be set on

// bar when it is added to collection

=;

="barStandard";

h=true;

uttonSize=true;

yMoreItemsOnMenu=true;

oundImage=new Bitmap(e(),"");

oundImagePosition=;//平铺覆盖

SetToolbarColorScheme(cheme);

// Must add bar to the bars collection so DotNetBarManager is aware of it

(bar);

// Set the inital docking line

ne=1;

// After manager is aware of the bar, we can dock it on appropriate side

de=;

// Account List

(CreateToolbarButton("bAccountList","Account

List","",""));

// Portofolio

(CreateToolbarButton("bPortofolio","Portofolio","",""));

// Bills and Deposits

(CreateToolbarButton("bBills","Bills &&

Deposits","",""));

// Reports

(CreateToolbarButton("bReports","Reports","",""));

// Cash Flow

(CreateToolbarButton("bCashFlow","Cash

Flow","",""));

// Budget

(CreateToolbarButton("bBudget","Budget","",""));

private void SetToolbarColorScheme(ColorScheme scheme)

{

}

// Setup toolbar custom

xt=;

tText=gb(247,222,156);

essedText=gb(247,222,156);

// This portion of color scheme changes is used only for overflow items

// i.e. if they cannot fit on toolbar they are displayed on menu

tBackground=gb(80,80,80);

tBackground2=;

tBorder=gb(80,80,80);

essedBackground=gb(91,91,91);

essedBackground2=;

essedBorder=gb(91,91,91);

pandedText=gb(247,222,156);

pandedBackground=gb(91,91,91);

pandedBackground2=;

pandedShadow=;

ckground=gb(91,91,91);

ckground2=;

rBackground=gb(91,91,91);

rBackground2=;

rder=;

de=gb(91,91,91);

de2=;

private ButtonItem CreateToolbarButton(string name, string text, string imageName, string

hotImageName)

{

}

ButtonItem button=new ButtonItem(name,text);

=new Bitmap(e(),imageName);

mage=new Bitmap(e(),hotImageName);

dImage=mage;

ckingStyle=;

Style=ndText;

osition=;

=;

return button;

6、 控件PanelEx的使用

(1)下图中的六部分都是PanelEx

(2)PanelEx有如上图的几种风格

(3)PanelEx在“Text”属性里,可以使用Html语言,可以加入超链接,只是只能链接到某个函数名,注意的是:必须将该函数,在“属性”—“事件”选项卡中的“MarkupLinkClick”事件中,进行关联。

7、

(1)弹出式菜单

设置该图左边图的代码如下:

// Setup side-bar, make sure that image that is used fits, or exceeds the height

// Side-bar will be displayed only for popup menus

//确定:在side-bar中使用的图都是可用的,

//另外,确定,图的大小要一定小于Side-Bar的高度

rImage si=new rImage();

e=new Bitmap(typeof(1),"");

// If image exceeds the size of the popup menu this specifies the image alignment

ent=;

// If there is no image specified gradient can be used

ntColor1=;

ntColor2=;

m_ideBar=si;

(2)弹出式工具栏

——(1)和(2)创建按钮(菜单选项)时,所用的函数一样,所用的风格一样,只是在最后弹出菜单时,使用的函数不一样,才导致的外观不一样

——这是Menu的风格设置

// Apply style

//设置风格

tBarStyle style

=

2003;

if(((tem)edItem).Text!="Office2003")

style=2005;

m_=style;

// MUST ALWAYS register popup with DotNetBar Manager if popup does not belong to ContextMenus

collection如果弹出式菜单不属于ContextMenu(即没有在属性“contextMenuBar1上的ContextMenuEx”,上进行相关设置)的话,该弹出式菜单必须在DotNetBar上进行注册

erPopup(m_PopupFromCode);

// Place the menu just below the button

Control ctrl=sender as Control;

Point p=oScreen(new Point(,));

m_enu(p);

m_ar(p);

——下面是Bar的风格设置

下面这两句才是弹出菜单显示效果不一样的原因。

(3)右键菜单

要想加入右键菜单,需要

1)加入控件“ContextMenuBar”

2)在“ContextMenuBar”上加入所需的右键菜单

示例:在“ContextMenuBar“上,右键,选择”Add Context Menu”,出现”“ButtomItem1,设置其”Name”属性,然后在该ButtomItem1上,单击右键,添加一系列button,这才是具体的右键菜单

3)在要加入右键菜单的控件上,设置属性“contextMenuBar1上的ContextMenuEx”,使该属性值与“右键菜单”ButtomItem1相关联即可

(4)ContextMenuEx弹出菜单时,激活的事件是PopupOpen,可以对弹出的菜单进行相应的设置

8 、控件ItemPanel和控件ItemContainer的使用

(1) 示例的使用效果

(2)控件ItemPanel和控件ItemContainer都是用来放其他控件的容器,只是

ItemPanel只能纵向放置,而ItemContainer都可以。

(3)

private void itemPanel2_ItemClick(object sender, rgs e)

{

if(sender is ButtonItem)

{

// Since chart selector buttons are in separate containers the Group setting

will not unselect

// the button from another container so we need to do it here

ButtonItem button = GetCheckedButton(, sender as ButtonItem);

}

if(button!=null)

d = false;

}

{

}

(4)private void columnContainer_Click(object sender, EventArgs e)

{

Visible( columnSelector );

d = true;

}

9、 控件ListViewEx的使用

(1)使用效果如下图

foreach(BaseItem item in parentCollection)

{

}

return null;

if(item is ButtonItem && item!=exclude && ((ButtonItem)item).Checked)

{

}

ButtonItem button = GetCheckedButton(ms, exclude);

if(button!=null)

return button;

return item as ButtonItem;

else if(ainer)

private ButtonItem GetCheckedButton(SubItemsCollection parentCollection, ButtonItem exclude)

(2)其中,

1)标题头部分通过属性“Columns”设置

2)内容部分

×)前面有图标部分,通过“Items”属性设置

×)后面的几列,通过“Items”的“SubItems”属性设置

3)可以通过设置该属性,可以使实现各种排列方式

10、Super Tool Tip

(1)使用效果

-------

(2)用法:

-------只是将控件Super Tool Bar添加到工程中,然后,再在要加入上述效果的控件的属性也中,找到“superTooltip上的SuperTooltip”,单击

。随后,会出现如上图所示的对话框,然后,就可以根据该对话框上的提示进行操作。

(3)值得注意的是:这里也可以使用Html语言,使用超链接(实际的效果类似于LinkButton控件),为该控件添加更多的功能

只不过的是:需要在SuperToolTip控件的的设置。

事件进行必要(4)通过程序为控件设置“superTooltip上的SuperTooltip”所应该设置的内容,下面以为TreeView控件的node节点进行相关设置进行说明:

1)首先,定义了一个NodeSuperTooltipProvider类,为每一个node对象,提供SuperTooltip功能

///

#region ISuperTooltipInfoProvider Members

/// Call this method to hide tooltip for given node.

public void Hide()

{

}

if(oltip!=null)

oltip(this,new EventArgs());

/// Call this method to show tooltip for given node.

//为给定的node显示tooltip

public void Show()

{

}

if(yTooltip!=null)

DisplayTooltip(this,new EventArgs());

/// Wrapper so SuperTooltips can be displayed for node objects.

///

public class NodeSuperTooltipProvider : Component,

{

private TreeNode m_Node=null;

public NodeSuperTooltipProvider(TreeNode node)

{

}

m_Node=node;

TooltipInfoProvider

//为给定的node隐藏tooltip

}

#endregion

/// Returns screen coordinates of object.

//返回node对象的屏幕坐标

public gle ComponentRectangle

{

}

public event EventHandler DisplayTooltip;

public event EventHandler HideTooltip;

get

{

}

Rectangle r=m_;

on=m_oScreen(on);

return r;

//下面的事件是程序自动提供的

2)为数TreeView的每一个node节点添加ToolTip

// Load SuperTooltip information for

TreeNode node=[0];

while(node!=null)

{

}

// Creates wrapper to provide SuperTooltip control access to the node object

NodeSuperTooltipProvider sp=new NodeSuperTooltipProvider(node);

=sp;

// Assign the wrapper to SuperTooltip control together with information

// about what to display on Super Tooltip for this node.

erTooltip(sp,

// Must expand node to get to the child nodes via NextVisibleNode

();

node=sibleNode;

new ooltipInfo("Header text for

"Additional body text for this node. nr"+,

null,null,));

"+,"",

3)和TreeView相关的一些操作

private TreeNode m_LastMouseOverNode=null;

e)

{

TreeNode nodeAt=eAt(e.X,e.Y);

private void treeView1_MouseMove(object sender, ventArgs

}

if(nodeAt!=m_LastMouseOverNode)

{

}

HideNodeTooltip();

if(nodeAt!=null)

{

}

m_LastMouseOverNode=nodeAt;

// Delayed display

();

private void ShowNodeTooltip(TreeNode node)

{

}

private void treeView1_MouseLeave(object sender, rgs e)

{

}

private void HideNodeTooltip()

{

}

private void tooltipDisplayDelay_Tick(object sender, rgs e)

{

();

if(m_LastMouseOverNode!=null)

if(m_LastMouseOverNode!=null)

{

}

NodeSuperTooltipProvider sp=m_ as

();

m_LastMouseOverNode=null;

// Hide tooltip when mouse leaves tree control

HideNodeTooltip();

();

if(node==null)

return;

NodeSuperTooltipProvider sp= as NodeSuperTooltipProvider;

();

m_LastMouseOverNode=node;

NodeSuperTooltipProvider;

e)

}

ShowNodeTooltip(m_LastMouseOverNode);

private void treeView1_MouseDown(object sender, ventArgs

{

}

private void superTooltipWithLink_MarkupLinkClick(object sender,

{

}

("Markup Link Clicked. href = " + );

// Hide tooltip if any

HideNodeTooltip();

LinkClickEventArgs e)

11、控件expandableSplitter和控件TabControl的使用

(1)控件expandableSplitter将容器的可显示区域分成两个可以调整大小的区域

建议用法:

1)从左到右,按顺序,一次,拖入如下控件,某个容器控件(Dock设置为Left),ExpandableSplitter控件(Dock设置为Left)以及另一个容器控件(Dock设置为Fill)

2)如果想实现“在控件expandableSplitter 的SplitterBar上单击一下,也能将该控件控制的区域收起或放开“的功能,可在属性中设置,

注意的是:在选项中,选择那个控件,那在单击“SplitterBar “时,就收起或打开哪个控件。

3)从网上下载的相关资料

DotNetBar中ExpandableSplitter使用技巧

Posted on 2008-01-10 21:39 flyingfish 阅读(671) 评论(0) 编辑 收藏 网摘 所属分类: C#编程

为了实现如下图1到图2效果,用ExpandableSplitter很方便,设置ExpandableSplitter的ExpandedControl属性为panelEx_Right即可。

但是想实现图3的效果,本以为用这个控件加上Form的Autosize属性即可。

没想搞了半天发现不管是form用autosize让panel_right的dock为fill,还是panel_right锚定都无法实现这个效果。

仔细想想,autosize肯定不行,其和dock在实现上就是是矛盾的,呵呵。

真是懒习惯了,动手加下边几句就可以解决,在这里记录一下。

public partial class Test : Form

{

//记录右侧Panel宽度

private int m_RightWidth = 0;

public Test()

{

InitializeComponent();

m_RightWidth = panelEx_;

}

private void expandableSplitter_Click(object sender, EventArgs e)

{

if (ed)

{

m_RightWidth = panelEx_;

-= m_RightWidth;

}

else

{

+= m_RightWidth;

}

}

}

另外记得设置MinExtra属性为0,不然ExpandableSplitter拖不到最边上。

(2)控件TabControl的使用比较简单

(3)关于控件TabControl的比较高级的用法示例

private void itemPanel1_ItemClick(object sender, rgs e)

{

}

private void ChangeTabColor(object sender, EventArgs e)

{

if(m_TabMouseDown!=null)

{

m_inedColor=(eTabItemColor)(typeof(eTabItemColor),((BaseItem)sender).Text);

}

}

private void SetTabStyle(eTabStripStyle style)

{

=style;

foreach(TabItem tab in )

inedColor=t;

}--------

ButtonItem button = sender as ButtonItem;

if(button==null)

return;

eTabStripStyle style = (eTabStripStyle)(typeof(eTabStripStyle), );

SetTabStyle(style);

Layout();

private void tabControl1_MouseDown(object sender, ventArgs e)

{

if(!=)

// Convert to screen based coordinates for context menu

Point p=new Point(e.X,e.Y);

Point pScreen=oScreen(p);

TabItem tab=t(p.X,p.Y);

if(tab!=null)

{

}

m_TabMouseDown=tab;

CreateContextMenu();

ButtonItem item=["tabColors"] as ButtonItem;

(pScreen);

return;

}

private void CreateContextMenu()

{

// Create one menu item for each entry in eTabItemColor

string[] names=es(typeof(eTabItemColor));

foreach(string s in names)

{

ButtonItem menuItem=new ButtonItem(s,s);

// Construct the image for the menu item

TabItem tabTemp=new TabItem();

ButtonItem item=new ButtonItem("tabColors","Tab Colors Context menu");

=2003;

(item);

if(ns("tabColors"))

return;

inedColor=(eTabItemColor)(typeof(eTabItemColor),s);

Bitmap bmp=new Bitmap(16,16,24bppRgb);

Graphics g=age(bmp);

try

{

(l);

Rectangle r=new Rectangle(1,1,14,14);

using(GradientBrush brush=new

GradientBrush(r,lor,lor2,lorGradientAngle))ctangle(brush,r);

}

}

12、控件Reflection(倒影) Image与控件Reflection Label可生成如下图所示的效果

{

}

ansparent(l);

=bmp;

+=new EventHandler(TabColor);

(menuItem);

e();

using(Pen pen=new Pen(ay,1))ctangle(pen,r);

}

finally

13、关于MonthCalendarAdv控件的使用

---下面两个图的区别,产生与属性“Dimension”

14、控件(1)使用效果

1)正常情况,即没有特殊设置时

的特殊使用

2)进行相应设置后

3)当然,这主要指的是周末的日期上的红叉“”,及不能被选择

(2)该功能和控件的

事件相关,下面是实现上述功能的具体代码:

private void monthCalendarAdv2_PaintLabel(object sender, DayPaintEventArgs e)

{

// Cross Sundays and disable selection

DayLabel day = sender as DayLabel;

if (day != null && > ue && eek == )

{

able = false; // Mark label as

ouse = false; // Do not track

ackground();

ext();

Rectangle r = ;

e(-2, -2);

SmoothingMode sm = ingMode;

ingMode = ias;

using (Pen pen = new Pen(gb(128, )))

{

ne(pen, r.X, r.Y, , );

ne(pen, , r.Y, r.X, );

}

ingMode = sm;

// Ensure that no part is rendered internally

Parts = ;

}

}

private void monthCalendarAdv2_MonthChanged(object sender, EventArgs e)

{

// You can use this event to add custom markers to the calendar for example mark appointments

// In this sample we'll just pick the day 8 days

DateTime date = s(8);

// DayLabel control is used to represents each date on calendar

DayLabel day = (date);

if (day != null) // Null will be returned if date is not displayed on calendar

{

// Display image on

= global::;

lign = Right;

ign = Left;

p = "Click image to see appointments";

// You can display the popup when day image is clicked with for example the

(new ButtonItem("appointment1", "10:45 AM Call Dave to setup

meeting"));

(new ButtonItem("appointment2", "12:05 PM Lunch with Kurt"));

}

}

15、控件DataTimeInput的使用

(1)可产生如下图所示的效果

(2)该图右上角的的出现与否取决于下面几个属性

(3)关于格式的控制

——主要与属性“Format”有关,其有如下几个选项:short、long、shorttime、longtime与custom等。

——注意:当使用“custom”自主控制格式时,要与属性“customFormat”配合使用。

(4)在输入框中是否有复选框,与属性“ShowCheckBox”有关

(5)输入框复选框是否处于“被选择(激活)”状态,与属性“LockUpdateChecked”有关

(6)至于,就相当于一个按钮(Buttom控件),可以添加一些特殊控制的代码。

(7)控件DataTimeInput的

事件集是很重要的,其中

是个重要的事件,下面是示例程序:

private void dateTimeInput11_MonthCalendar_PaintLabel(object sender,

ntEventArgs e)

{

el day = sender as

el;

if (day == null || == ue) return;

// Cross all weekend days and disable selection

if ((eek == ay || eek == ) &&

!= s(1))

{

able = false; // Mark label as

ouse = false; // Do not track

ackground();

ext();

Rectangle r = ;

e(-2, -2);

SmoothingMode sm = ingMode;

ingMode = ias;

ne(, r.X, r.Y, , );

ne(, , r.Y, r.X, );

ingMode = sm;

// Ensure that no part is rendered internally

Parts = ;

}

// Mark

else if (day != null && == s(1))

{

ackground();

ext();

SmoothingMode sm = ingMode;

ingMode = ias;

Rectangle r = ;

--;

--;

using(Pen pen = new Pen(gb(128, )))

lipse(pen, r);

ingMode = sm;

// Ensure that no part is rendered internally

Parts = ;

}

}

(8)用户定义的日期/时间格式(Format 函数)

C#时间格式

有时候我们要对时间进行转换,达到不同的显示效果

默认格式为:2005-6-6 14:33:34

如果要换成成200506,06-2005,2005-6-6或更多的该怎么办呢

我们要用到:ng的方法(String, IFormatProvider)

using System;

using ization;

String format="D";

DateTime date=DataTime,Now;

(ng(format, antInfo));

结果输出

Thursday, June 16, 2005

参数format格式详细用法

格式字符 关联属性/说明

d ShortDatePattern

D LongDatePattern

f 完整日期和时间(长日期和短时间)

F FullDateTimePattern(长日期和长时间)

g 常规(短日期和短时间)

G 常规(短日期和长时间)

m、M MonthDayPattern

r、R RFC1123Pattern

s 使用当地时间的 SortableDateTimePattern(基于 ISO 8601)

t ShortTimePattern

T LongTimePattern

u UniversalSortableDateTimePattern 用于显示通用时间的格式

U 使用通用时间的完整日期和时间(长日期和长时间)

y、Y YearMonthPattern

下表列出了可被合并以构造自定义模式的模式。这些模式是区分大小写的焕纾侗稹癕M”,但不识别“mm”。如果自定义模式包含空白字符或用单引号括起来的字符,则输出字符串页也将包含这些字符。未定义为格式模式的一部分或未定义为格式字符的字符按其原义复制。

格式模式 说明

d 月中的某一天。一位数的日期没有前导零。

dd 月中的某一天。一位数的日期有一个前导零。

ddd 周中某天的缩写名称,在 AbbreviatedDayNames 中定义。

dddd 周中某天的完整名称,在 DayNames 中定义。

M 月份数字。一位数的月份没有前导零。

MM 月份数字。一位数的月份有一个前导零。

MMM 月份的缩写名称,在 AbbreviatedMonthNames 中定义。

MMMM 月份的完整名称,在 MonthNames 中定义。

y 不包含纪元的年份。如果不包含纪元的年份小于 10,则显示不具有前导零的年份。

yy 不包含纪元的年份。如果不包含纪元的年份小于 10,则显示具有前导零的年份。

yyyy 包括纪元的四位数的年份。

gg 时期或纪元。如果要设置格式的日期不具有关联的时期或纪元字符串,则忽略该模式。

h 12 小时制的小时。一位数的小时数没有前导零。

hh 12 小时制的小时。一位数的小时数有前导零。

H 24 小时制的小时。一位数的小时数没有前导零。

HH 24 小时制的小时。一位数的小时数有前导零。

m 分钟。一位数的分钟数没有前导零。

mm 分钟。一位数的分钟数有一个前导零。

s 秒。一位数的秒数没有前导零。

ss 秒。一位数的秒数有一个前导零。

f 秒的小数精度为一位。其余数字被截断。

ff 秒的小数精度为两位。其余数字被截断。

fff 秒的小数精度为三位。其余数字被截断。

ffff 秒的小数精度为四位。其余数字被截断。

fffff 秒的小数精度为五位。其余数字被截断。

ffffff 秒的小数精度为六位。其余数字被截断。

fffffff 秒的小数精度为七位。其余数字被截断。

t 在 AMDesignator 或 PMDesignator 中定义的 AM/PM 指示项的第一个字符(如果存在)。

tt 在 AMDesignator 或 PMDesignator 中定义的 AM/PM 指示项(如果存在)。

z 时区偏移量(“+”或“-”后面仅跟小时)。一位数的小时数没有前导零。例如,太平洋标准时间是“-8”。

zz 时区偏移量(“+”或“-”后面仅跟小时)。一位数的小时数有前导零。例如,太平洋标准时间是“-08”。

zzz 完整时区偏移量(“+”或“-”后面跟有小时和分钟)。一位数的小时数和分钟数有前导零。例如,太平洋标准时间是“-08:00”。

: 在 TimeSeparator 中定义的默认时间分隔符。

/ 在 DateSeparator 中定义的默认日期分隔符。

% c 其中 c 是格式模式(如果单独使用)。如果格式模式与原义字符或其他格式模式合并,则可以省略“%”字符。

c 其中 c 是任意字符。照原义显示字符。若要显示反斜杠字符,请使用“”。

只有上面第二个表中列出的格式模式才能用于创建自定义模式;在第一个表中列出的标准格式字符不能用于创建自定义模式。自定义模式的长度至少为两个字符;例如,

ng( "d") 返回 DateTime 值;“d”是标准短日期模式。

ng( "%d") 返回月中的某天;“%d”是自定义模式。

ng( "d ") 返回后面跟有一个空白字符的月中的某天;“d”是自定义模式。

比较方便的是,上面的参数可以随意组合,并且不会出错,多试试,肯定会找到你要的时间格式

如要得到2005年06月 这样格式的时间

16、IntegerInput控件和DoubleInput控件的用法类似

------(1)关于格式的控制,这两个控件有好多地方与DateTimeInput控件相似,这里介绍一个不同的

控件激活前是这样的,但是,当控件激活后,就变成这样的,然后,就和其他设置的IntegerInput控件的用法一致了。

——(2)图标表示“自增/自减”,与属性有关,而增量与属性——(3)与增量有关:怎么实现任意步长?

——(4)数字的格式化

1)内置类型的字母格式

有一种格式命令以单个字母开头,表示下列设置:

G—常规,E 或 F 中较短的

F—浮点数,常规表示法

E—用 E 表示法表示的浮点数(其中,E 代表 10 的次幂)

N—带有分隔符的浮点数(在美国为逗号)

C—货币,带有货币符号和分隔符(在美国为逗号)

D—十进制数,仅用于整型

X—十六进制数,仅用于整型

有关。

字母可以后跟一个数字,根据字母的不同,该数字可以表示总位数、有效位数或小数点后面的位数。

2)下面是字母格式的一些示例:

double pi = ;

double p0 = pi * 10000;

int i = 123;

ine("浮点格式,无分隔符(逗号)");

ine("pi, Left {0, -25}", pi); // 3.97931

ine("p0, Rt. {0, 25}", p0); // 3.97931

ine("pi, E {0, 25:E}", pi); // 3.1416E+000

ine("使用 E 和 F 格式,小数点后保留 n(此处为 4)位");

ine("pi, E4 {0, 25:E4}", pi); // 3.1416E+000

ine("pi, F4 {0, 25:F4}", pi); // 3.1416

ine("使用 G 格式,保留 4 位有效数字——如果需要请使用 E 格式");

ine("pi, G4 {0, 25:G4}", pi); // 3.142

ine("p0, G4 {0, 25:G4}", p0); // 3.142E4

ine("N 和 C 格式带有逗号(分隔符)," +

"默认小数点后保留两位,四舍五入。");

ine("p0, N {0, 25:N}", p0); // 31,415.93

ine("p0, N4 {0, 25:N4}", p0); // 31,415.9265

ine("p0, C {0,25:C}", pi); // $3.14

ine("D 和 X 格式仅用于整型," +

"非整型将产生格式异常——X 指十六进制");

ine("i, D {0, 25:D}", i ); // 123

ine("i, D7 {0, 25:D7}", i ); // 0000123

ine("i, X {0, 25:X}", i ); // 7B

ine("i, X8 {0, 25:X8}", i ); // 0000007B

图片格式

与字母格式不同,formatstring 可以包含“图片格式”。下面是从代码中摘录的几个实例。(这类似于 Basic

中的“Print Using”语句。)图片格式功能甚至包括以不同方式设置负数、正数和零的格式的能力。还有几个图片格式功能,下面的示例中未包括在内。有关详细信息,请参阅“.NET 框架开发人员指南”或文档中的主题图片格式数字串(英文)。

在下例中您将注意到,好心的博士既使用了“#”字符,又使用了“0”字符。如果相应的数字是前导零或尾随零,“#”字符就会替换为空值。无论相应数字的值如何,“0”字符都会被替换为零字符 — 因此,数字将会被零填补。句号(如果有的话)表示小数分隔符的位置。

17、下面的代码可以将下图,左侧的图标和右侧的图标相互拖动入对方

private void listView1_DragEnter(object sender, entArgs e)

{

}

if(m_InternalDragDrop)

return;

=;

=;

if(a(typeof(ButtonItem))==null)

else