好的代码给大家共享

chencheng45 2006-08-23 09:06:26
#region Private Methods

/// <summary>
/// Sets the ActorDisplay to display no Actor.
/// Disables all of the GUI controls of the ActorDisplay.
/// </summary>
private void InitEmpty()
{
initializing=true;

saveX = "0";
saveY = "0";
saveW = "0";
saveH = "0";
saveFilled =false;
saveColor =Color.White;
saveBordered=true;
saveBrdColor=Color.Black;
saveText ="";
saveTxtColor=Color.Black;

UpdateGUI();
noActor=true;
this.tBox_LocX.Enabled=true;
this.tBox_LocY.Enabled=true;
this.tBox_Width.Enabled=true;
this.tBox_Height.Enabled=true;
this.check_Filled.Enabled=true;
this.btn_ColorPick.Enabled=true;
this.check_Bordered.Enabled=true;
this.btn_BrdColorPick.Enabled=true;
this.tBox_Text.Enabled=true;
this.btn_TxtColorPick.Enabled=true;

initializing=false;
}
/// <summary>
/// Sets the ActorDisplay to display the given Actor.
/// Enables all of the GUI Controls of the ActorDisplay.
/// </summary>
/// <param name="inA">The Actor to be displayed.</param>
private void SaveActor(Actor inA)
{
initializing=true;
saveX = inA[UseCaseAnchors.TopLeft].CenterX.ToString();
saveY = inA[UseCaseAnchors.TopLeft].CenterY.ToString();
saveW = inA.Width.ToString();
saveH = inA.Height.ToString();
saveFilled = inA.Filled;
saveColor = inA.Color;
saveBordered= inA.Bordered;
saveBrdColor= inA.BrdColor;
saveText = inA.Text;
saveTxtColor= inA.TxtColor;

UpdateGUI();
noActor=false;
this.tBox_LocX.Enabled=true;
this.tBox_LocY.Enabled=true;
this.tBox_Width.Enabled=true;
this.tBox_Height.Enabled=true;
this.check_Filled.Enabled=true;
this.btn_ColorPick.Enabled=true;
this.check_Bordered.Enabled=true;
this.btn_BrdColorPick.Enabled=true;
this.tBox_Text.Enabled=true;
this.btn_TxtColorPick.Enabled=true;
initializing=false;
}

/// <summary>
/// Updates the GUI Control of the ActorDisplay to match
/// the values in the private fields of the ActorDisplay.
/// </summary>
private void UpdateGUI()
{
this.tBox_LocX.Text=saveX;
this.tBox_LocY.Text=saveY;
this.tBox_Width.Text=saveW;
this.tBox_Height.Text=saveH;
this.check_Filled.Checked=saveFilled;
this.pnl_Color.BackColor=saveColor;
this.check_Bordered.Checked=saveBordered;
this.pnl_BrdColor.BackColor=saveBrdColor;
this.tBox_Text.Text=saveText;
this.pnl_TxtColor.BackColor=saveTxtColor;
}
/// <summary>
/// Announces (via MessageBox) that the specified coordinate
/// is invalid.
/// </summary>
/// <param name="s">The string representation of the invalid coordinate.</param>
private void AnnounceBadCoordinate(string s)
{
StringBuilder sb = new StringBuilder("The value you specified for the actor's location\n");
sb.Append("coordinate ("+s+") is not a valid coordinate.\n");
sb.Append("The coordinate will be reset to its previous value.\n");
MessageBox.Show(this, sb.ToString(), "Invalid Coordinate:");
}
/// <summary>
/// Announces (via MessageBox) that the specified dimension
/// is invalid.
/// </summary>
/// <param name="s">The string representation of the invalid dimension.</param>
private void AnnounceBadDimension(string s)
{
StringBuilder sb = new StringBuilder("The value you specified for the actor's dimension\n");
sb.Append("("+s+") is not a valid dimension.\n");
sb.Append("The dimension will be reset to its previous value.\n");
MessageBox.Show(this, sb.ToString(), "Invalid Dimension:");
}

#region Handle events from the GUI Controls

/// <summary>
/// Handles the Leave (i.e. LooseFocus) event for the text boxes used to
/// display the coordinates of the Actor's Location.
/// The new coordinate is validated (see ValidLocationCoordinate method). If
/// the new coordinate is valid (and different from the previous value
/// of the same coordinate), the OnLocationChanged method is invoked
/// to fire a new ActorLocationChanged event. If the new coordinate is invalid,
/// the AnnounceBadCoordinate method is invoked.
/// </summary>
/// <param name="sender">The object sending the event.</param>
/// <param name="e">The System.EventArgs describing the event.</param>
private void locCoord_LooseFocus(object sender, System.EventArgs e)
{
string ntxt ="";
string otxt ="";
Coordinate whichCoordinate = Coordinate.X;

TextBox tbox = sender as TextBox;
if(tbox==null) return;

switch(tbox.Name)
{
case "tBox_LocX":
otxt = saveX;
ntxt = this.tBox_LocX.Text;
whichCoordinate = Coordinate.X;
break;
case "tBox_LocY":
otxt = saveY;
ntxt = this.tBox_LocY.Text;
whichCoordinate = Coordinate.Y;
break;
default:
return;
}
float newVal = 0.0f;
if(ValidLocationCoordinate(ntxt, ref newVal))
{
switch(whichCoordinate)
{
case Coordinate.X:
saveX = ntxt;
break;
case Coordinate.Y:
saveY = ntxt;
break;
default:
break;
}
if(!initializing)
OnLocationChanged(new ActorLocationChangedEventArgs(whichCoordinate, newVal));
}
else
{
AnnounceBadCoordinate(ntxt);
tbox.Text=otxt;
}
}
/// <summary>
/// Handles the Leave (i.e. LooseFocus) event for the text boxes used to
/// display the dimensions of the Actor.
/// The new dimension is validated (see ValidDimension method). If
/// the new dimension is valid (and different from the previous value
/// of the same coordinate), the OnActorResized method is invoked
/// to fire a new ActorResized event. If the new coordinate is invalid,
/// the AnnounceBadDimension method is invoked.
/// </summary>
/// <param name="sender">The object sending the event.</param>
/// <param name="e">The System.EventArgs describing the event.</param>
private void dimension_LooseFocus(object sender, System.EventArgs e)
{
string ntxt ="";
string otxt ="";

TextBox tbox = sender as TextBox;
if(tbox==null) return;

switch(tbox.Name)
{
case "tBox_Width":
ntxt = this.tBox_Width.Text;
otxt = saveW;
break;
case "tBox_Height":
ntxt = this.tBox_Height.Text;
otxt = saveH;
break;
default:
return;
}
float f = 0.0f;
if(ValidDimension(ntxt, ref f))
{
switch(tbox.Name)
{
case "tBox_Width":
saveW=ntxt;
break;
case "tBox_Height":
saveH=ntxt;
break;
default:
return;
}
float fw = float.Parse(this.tBox_Width.Text);
float fh = float.Parse(this.tBox_Height.Text);
if(!initializing)
OnActorResized(new ActorResizeEventArgs(fw, fh));
}
else
{
AnnounceBadDimension(ntxt);
tbox.Text=otxt;
}
}
/// <summary>
/// Handles the CheckedChanged event of the check_Filled checkbox.
/// Invokes the OnActorFilledChanged method to fire a new
/// ActorFilledChanged event.
/// </summary>
/// <param name="sender">The object sending the event.</param>
/// <param name="e">The System.EventArgs describing the event.</param>
private void check_Filled_CheckedChanged(object sender, System.EventArgs e)
{
saveFilled = this.check_Filled.Checked;
if(!initializing)
OnActorFilledChanged(new ActorFilledChangedEventArgs(saveFilled));
}
/// <summary>

private void check_Bordered_CheckedChanged(object sender, System.EventArgs e)
{
saveBordered = this.check_Bordered.Checked;
if(!initializing)
OnActorBorderedChanged(new ActorBorderedChangedEventArgs(saveFilled));
}
...全文
313 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
swing05 2006-11-19
  • 打赏
  • 举报
回复
mark!有空在看!呵呵
chencheng45 2006-11-19
  • 打赏
  • 举报
回复
Customize the EditForm in the SharePoint Service v3.0
http://office.microsoft.com/en-us/sharepointdesigner/HA101191111033.aspx
chencheng45 2006-11-19
  • 打赏
  • 举报
回复
http://office.microsoft.com/en-us/sharepointdesigner/HA101191111033.aspx
chencheng45 2006-11-16
  • 打赏
  • 举报
回复
Introduction

Drop-down menus in Windows SharePoint Services and SharePoint Portal Server 2003 enable actions that relate to a specific document in a document library to be viewed and invoked. This article shows how these document context menus can be extended to add custom menu items. The document first explains how SharePoint document library context menus work, and then demonstrates how custom menu items can be added.



The Business Problem

Windows SharePoint Services (WSS) document libraries provide a location to store and share files and documents. The WSS user interface provides a context sensitive drop-down menu for each item stored in a document library (Figure 1). A common requirement is the ability to customise this menu to add new actions. For example you might wish to add an option to enable a document to be copied or moved to another location or emailed to a colleague.



Figure 1 Document context menu in a SharePoint Document Library



The solution and sample code presented in this article shows how a custom menu item can be created that sends an email link to the relevant document to another user.



Solution Overview

The WSS document context menu is generated by client-side Javascript. The script to display these menus is located in a file called ows.js in the folder \Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033 on the SharePoint server. The AddDocLibMenuItems function in ows.js is responsible for generating the drop-down menus. The AddDocLibMenuItems implementation provides a hook through which additional menu items can be added to the context menu. The first few lines of this function read:



function AddDocLibMenuItems(m, ctx)

{

if (typeof(Custom_AddDocLibMenuItems) != “undefined”)

{

if (Custom_AddDocLibMenuItems(m, ctx))

return;

}



..etc..



This piece of code is checking whether a function called Custom_AddDocLibMenuItems is defined, and if it is then calling it. By implementing this function in a page containing a document library web part, we can extend the context menu, adding our own menu items.



The Custom Menu Items Web Part

So, how can we add a custom piece of JavaScript to a SharePoint page? We need to make sure that the technique we use is configurable and flexible, and that we don’t change any of the built-in script or features of SharePoint so that our implementation is not overwritten by any SharePoint upgrades or service packs that may be deployed in the future.

Fortunately SharePoint provides a convenient mechanism for doing this – the Content Editor Web Part. The Content Editor Web Part enables custom HTML and script to be added to a page and delivered to the browser.



Adding the Web Part to a Page

In SharePoint, navigate to a page with a document library web part on it, or add one to an existing page.

On the Modify Shared Page menu, point to Add Web Parts and click on Browse.

Drag the Content Editor Web Part from the tool pane onto the page, then click Open Tool Pane link in the web part.

In the Layout section clear the Visible on Page checkbox. This means the web part is not visible to the end-user, but the script we add to the web part is still delivered to the client browser. In the page design view, you can still see the web part, but it is marked as hidden. If you wish you can also change the title of the web part in the Appearance section of the tool pane.



Figure 2 Hidden Web Part in Design View



From the tool pane, open the Source Editor and insert the following script:



<script language="javascript">

function Custom_AddDocLibMenuItems(m, ctx)

{

var strDisplayText = "Say Hello World!";

var strAction = "alert('Hello World')";

var strImagePath = "";



// Add our new menu item

CAMOpt(m, strDisplayText, strAction, strImagePath);



// add a separator to the menu

CAMSep(m);



// false means that the standard menu items should also be rendered

return false;

}

</script>



Click Save in the Source Editor, and then click OK in the tool pane.

Now test the web part by opening a document library drop-down menu on the same page. You should see the new menu item at the top of the menu with a separator bar splitting it from the rest of the menu.



Figure 3 Drop-down menu with Hello World item added



How It Works

The Custom_ AddDocLibMenuItems function takes two parameters. The first parameter, called m, represents the menu object itself; the second parameter, ctx, provides HTTP context information about the web request.

Adding a menu item to the menu requires just one function call:

CAMOpt(m, strDisplayText, strAction, strImagePath);



The CAMOpt function takes four parameters: the menu object to add the new item to, the display text of the menu item, the javascript action to perform when the item is clicked and a path to an image file to associate with the item.

A call to the CAMSep function adds the separator bar to the menu. Both these functions are defined in the menu.js file on the SharePoint server.

Finally, the function returns false to the caller. This makes sure the standard menu items are also added to the menu; returning true indicates that these items should not be added.



Debugging the Web Part

To debug the web part, insert a debugger statement into the web part JavaScript:

debugger;



Provided a suitable debugger (such as Visual Studio.NET or the Microsoft Script Debugger) is installed, this statement causes Internet Explorer to break into the script when it is run, and offer the opportunity to start debugging.



Note: By default Internet Explorer disables script debugging. To make sure script debugging is enabled, open the Internet Options dialog from the Tools menu, and on the Advanced tab clear the Disable script debugging check box.



Once in the debugger, you can use the watch window to examine the variables that are available. Interesting variables to examine are m – the menu object, ctx which contains HTTP context information and itemTable which contains information about the list item the menu is associated with.



The Send Mail Web Part

Now we have figured out the principles of customising the drop down menus, the next step is to have them do something useful! The following script adds a menu item that sends an email link to the relevant document. It works by parsing the document URL out of the itemTable object and creating an action that instructs Internet Explorer to start a new mail message.

To use create this web part, simply follow the same steps that we used to create the Hello World menu item, using this script instead:



<script language="javascript">



function Custom_AddDocLibMenuItems(m, ctx)

{

var strDisplayText = "Send Link By Email...";

var strAction;

var strImagePath = "";



// parse the URL out of the itemTable

var URL = "";

var index = itemTable.innerHTML.indexOf("href=");

if (index > 0)

{

var str = itemTable.innerHTML.substr(index + 6);

index = str.indexOf('"');

if (index > 0)

{

URL = str.substr(0, index);

}

}



if (URL != "")

{

strAction = 'window.navigate("mailto:%20?subject=Take a look at this document...&body=<' + URL + '>")';



// Add menu item

CAMOpt(m, strDisplayText, strAction, strImagePath);



// add a separator to the menu

CAMSep(m);

}



return false;

}

</script>



Clicking the custom menu item opens a new email message with the URL of the document in the body of the message.

dyw31415926 2006-08-24
  • 打赏
  • 举报
回复
没有任何一句注释,谁写的代码,肯定不是高手
renmasheshou 2006-08-24
  • 打赏
  • 举报
回复
什么代码呀~~~
jack_man_ 2006-08-24
  • 打赏
  • 举报
回复
……
diandian82 2006-08-24
  • 打赏
  • 举报
回复
真好
giant2006 2006-08-24
  • 打赏
  • 举报
回复
太高深了
路人霆 2006-08-24
  • 打赏
  • 举报
回复
什么东西?
Tigggeeer 2006-08-24
  • 打赏
  • 举报
回复
好~
可惜我看不懂
snwyq 2006-08-24
  • 打赏
  • 举报
回复
區:北京
年限:2年
技術:.Net BS开发
工資:avg>>5K + 福利,几乎不加班,工作开心,心情愉快。
公司性質:汽车门户网站。

PS: 透露点消息,我们公司正在招.net BS开发人员,如果哪位同仁想换工作,是一个不错的机会选择,加richard_wung@hotmail.com 说应聘即可!
Jianyi 2006-08-23
  • 打赏
  • 举报
回复
好在哪里?
wuhuabucai 2006-08-23
  • 打赏
  • 举报
回复
????????????????????
chencheng45 2006-08-23
  • 打赏
  • 举报
回复
this.btn_TxtColorPick.Click += new System.EventHandler(this.btn_TxtColorPick_Click);
//
// lbl_TextColor
//
this.lbl_TextColor.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lbl_TextColor.Location = new System.Drawing.Point(10, 160);
this.lbl_TextColor.Name = "lbl_TextColor";
this.lbl_TextColor.Size = new System.Drawing.Size(55, 20);
this.lbl_TextColor.TabIndex = 48;
this.lbl_TextColor.Text = "Txt Color:";
this.lbl_TextColor.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// tBox_Text
//
this.tBox_Text.Location = new System.Drawing.Point(70, 130);
this.tBox_Text.Name = "tBox_Text";
this.tBox_Text.Size = new System.Drawing.Size(170, 20);
this.tBox_Text.TabIndex = 47;
this.tBox_Text.Text = "";
this.tBox_Text.TextChanged += new System.EventHandler(this.tBox_Text_TextChanged);
//
// lbl_Text
//
this.lbl_Text.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lbl_Text.Location = new System.Drawing.Point(10, 130);
this.lbl_Text.Name = "lbl_Text";
this.lbl_Text.Size = new System.Drawing.Size(50, 20);
this.lbl_Text.TabIndex = 46;
this.lbl_Text.Text = "Text:";
this.lbl_Text.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// btn_BrdColorPick
//
this.btn_BrdColorPick.Location = new System.Drawing.Point(190, 100);
this.btn_BrdColorPick.Name = "btn_BrdColorPick";
this.btn_BrdColorPick.Size = new System.Drawing.Size(50, 20);
this.btn_BrdColorPick.TabIndex = 45;
this.btn_BrdColorPick.Text = "&Pick...";
this.btn_BrdColorPick.Click += new System.EventHandler(this.btn_BrdColorPick_Click);
//
// check_Bordered
//
this.check_Bordered.Location = new System.Drawing.Point(65, 100);
this.check_Bordered.Name = "check_Bordered";
this.check_Bordered.Size = new System.Drawing.Size(20, 20);
this.check_Bordered.TabIndex = 44;
this.check_Bordered.CheckedChanged += new System.EventHandler(this.check_Bordered_CheckedChanged);
//
// lbl_Bordered
//
this.lbl_Bordered.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lbl_Bordered.Location = new System.Drawing.Point(5, 100);
this.lbl_Bordered.Name = "lbl_Bordered";
this.lbl_Bordered.Size = new System.Drawing.Size(50, 20);
this.lbl_Bordered.TabIndex = 43;
this.lbl_Bordered.Text = "Border?";
this.lbl_Bordered.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// btn_ColorPick
//
this.btn_ColorPick.Location = new System.Drawing.Point(190, 70);
this.btn_ColorPick.Name = "btn_ColorPick";
this.btn_ColorPick.Size = new System.Drawing.Size(50, 20);
this.btn_ColorPick.TabIndex = 42;
this.btn_ColorPick.Text = "&Pick...";
this.btn_ColorPick.Click += new System.EventHandler(this.btn_ColorPick_Click);
//
// check_Filled
//
this.check_Filled.Location = new System.Drawing.Point(65, 70);
this.check_Filled.Name = "check_Filled";
this.check_Filled.Size = new System.Drawing.Size(20, 20);
this.check_Filled.TabIndex = 41;
this.check_Filled.CheckedChanged += new System.EventHandler(this.check_Filled_CheckedChanged);
//
// lbl_Filled
//
this.lbl_Filled.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lbl_Filled.Location = new System.Drawing.Point(5, 70);
this.lbl_Filled.Name = "lbl_Filled";
this.lbl_Filled.Size = new System.Drawing.Size(50, 20);
this.lbl_Filled.TabIndex = 40;
this.lbl_Filled.Text = "Filled?";
this.lbl_Filled.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// tBox_Height
//
this.tBox_Height.Location = new System.Drawing.Point(190, 40);
this.tBox_Height.Name = "tBox_Height";
this.tBox_Height.Size = new System.Drawing.Size(50, 20);
this.tBox_Height.TabIndex = 39;
this.tBox_Height.Text = "";
this.tBox_Height.Leave += new System.EventHandler(this.dimension_LooseFocus);
//
// lbl_Height
//
this.lbl_Height.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lbl_Height.Location = new System.Drawing.Point(130, 40);
this.lbl_Height.Name = "lbl_Height";
this.lbl_Height.Size = new System.Drawing.Size(50, 20);
this.lbl_Height.TabIndex = 38;
this.lbl_Height.Text = "Height:";
this.lbl_Height.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// tBox_Width
//
this.tBox_Width.Location = new System.Drawing.Point(65, 40);
this.tBox_Width.Name = "tBox_Width";
this.tBox_Width.Size = new System.Drawing.Size(50, 20);
this.tBox_Width.TabIndex = 37;
this.tBox_Width.Text = "";
this.tBox_Width.Leave += new System.EventHandler(this.dimension_LooseFocus);
//
// lbl_Width
//
chencheng45 2006-08-23
  • 打赏
  • 举报
回复
/// <summary>
/// Fires a new ActorBorderedChanged event if any handler is registered.
/// </summary>
/// <param name="e">The ActorBorderedChangedEventArgs describing the event.</param>
protected virtual void OnActorBorderedChanged(ActorBorderedChangedEventArgs e)
{ if(ActorBorderedChanged!=null) ActorBorderedChanged(this, e); }
/// <summary>
/// Fires a new ActorColorChanged event if any handler is registered.
/// </summary>
/// <param name="e">The ActorColorChangedEventArgs describing the event.</param>
protected virtual void OnActorColorChanged(ActorColorChangedEventArgs e)
{ if(ActorColorChanged!=null) ActorColorChanged(this, e); }
/// <summary>
/// Fires a new ActorColorChanged event if any handler is registered.
/// </summary>
/// <param name="e">The ActorColorChangedEventArgs describing the event.</param>
protected virtual void OnActorTextColorChanged(ActorColorChangedEventArgs e)
{ if(ActorTextColorChanged!=null) ActorTextColorChanged(this, e); }
/// <summary>
/// Fires a new ActorColorChanged event if any handler is registered.
/// </summary>
/// <param name="e">The ActorColorChangedEventArgs describing the event.</param>
protected virtual void OnActorBorderColorChanged(ActorColorChangedEventArgs e)
{ if(ActorBorderColorChanged!=null) ActorBorderColorChanged(this, e); }
/// <summary>
/// Fires a new ActorTextChanged event if any handler is registered.
/// </summary>
/// <param name="e">The ActorTextChangedEventArgs describing the event.</param>
protected virtual void OnActorTextChanged(ActorTextChangedEventArgs e)
{ if(ActorTextChanged!=null) ActorTextChanged(this, e); }


#endregion


#endregion

#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()
{
this.pnl_TxtColor = new System.Windows.Forms.Panel();
this.pnl_BrdColor = new System.Windows.Forms.Panel();
this.pnl_Color = new System.Windows.Forms.Panel();
this.btn_TxtColorPick = new System.Windows.Forms.Button();
this.lbl_TextColor = new System.Windows.Forms.Label();
this.tBox_Text = new System.Windows.Forms.TextBox();
this.lbl_Text = new System.Windows.Forms.Label();
this.btn_BrdColorPick = new System.Windows.Forms.Button();
this.check_Bordered = new System.Windows.Forms.CheckBox();
this.lbl_Bordered = new System.Windows.Forms.Label();
this.btn_ColorPick = new System.Windows.Forms.Button();
this.check_Filled = new System.Windows.Forms.CheckBox();
this.lbl_Filled = new System.Windows.Forms.Label();
this.tBox_Height = new System.Windows.Forms.TextBox();
this.lbl_Height = new System.Windows.Forms.Label();
this.tBox_Width = new System.Windows.Forms.TextBox();
this.lbl_Width = new System.Windows.Forms.Label();
this.tBox_LocY = new System.Windows.Forms.TextBox();
this.lbl_LocY = new System.Windows.Forms.Label();
this.tBox_LocX = new System.Windows.Forms.TextBox();
this.lbl_LocX = new System.Windows.Forms.Label();
this.lbl_Location = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// pnl_TxtColor
//
this.pnl_TxtColor.BackColor = System.Drawing.Color.Transparent;
this.pnl_TxtColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pnl_TxtColor.Location = new System.Drawing.Point(70, 160);
this.pnl_TxtColor.Name = "pnl_TxtColor";
this.pnl_TxtColor.Size = new System.Drawing.Size(110, 20);
this.pnl_TxtColor.TabIndex = 52;
//
// pnl_BrdColor
//
this.pnl_BrdColor.BackColor = System.Drawing.Color.Transparent;
this.pnl_BrdColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pnl_BrdColor.Location = new System.Drawing.Point(90, 100);
this.pnl_BrdColor.Name = "pnl_BrdColor";
this.pnl_BrdColor.Size = new System.Drawing.Size(90, 20);
this.pnl_BrdColor.TabIndex = 51;
//
// pnl_Color
//
this.pnl_Color.BackColor = System.Drawing.Color.Transparent;
this.pnl_Color.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pnl_Color.Location = new System.Drawing.Point(90, 70);
this.pnl_Color.Name = "pnl_Color";
this.pnl_Color.Size = new System.Drawing.Size(90, 20);
this.pnl_Color.TabIndex = 50;
//
// btn_TxtColorPick
//
this.btn_TxtColorPick.Location = new System.Drawing.Point(190, 160);
this.btn_TxtColorPick.Name = "btn_TxtColorPick";
this.btn_TxtColorPick.Size = new System.Drawing.Size(50, 20);
this.btn_TxtColorPick.TabIndex = 49;
this.btn_TxtColorPick.Text = "P&ick...";
chencheng45 2006-08-23
  • 打赏
  • 举报
回复
private void btn_ColorPick_Click(object sender, System.EventArgs e)
{
ColorDialog cd = new ColorDialog();
cd.AllowFullOpen=false;
cd.SolidColorOnly=true;
cd.AnyColor=false;
cd.Color=saveColor;
DialogResult dr = cd.ShowDialog(this);
if(dr==DialogResult.OK)
{
Color newColor = cd.Color;
if(newColor!=saveColor)
{
saveColor = newColor;
this.pnl_Color.BackColor=saveColor;
if(!initializing)
OnActorColorChanged(new ActorColorChangedEventArgs(saveColor));
}
}
}
/// <summary>
/// Handles the Click event of the btn_TxtColorPick Button.
/// Displays a ColorDialog to let the user select a new Color.
/// If the selected Color is different than the previous one,
/// the pnl_TxtColor panel is colored in the choosen Color, and
/// the OnActorTextColorChanged method is invoked to fire a new
/// ActorTextColorChanged event.
/// </summary>
/// <param name="sender">The object sending the event.</param>
/// <param name="e">The System.EventArgs describing the event.</param>
private void btn_TxtColorPick_Click(object sender, System.EventArgs e)
{
ColorDialog cd = new ColorDialog();
cd.AllowFullOpen=false;
cd.SolidColorOnly=true;
cd.AnyColor=false;
cd.Color=saveTxtColor;
DialogResult dr = cd.ShowDialog(this);
if(dr==DialogResult.OK)
{
Color newColor = cd.Color;
if(newColor!=saveTxtColor)
{
saveTxtColor = newColor;
this.pnl_TxtColor.BackColor=saveTxtColor;
if(!initializing)
OnActorTextColorChanged(new ActorColorChangedEventArgs(saveColor));
}
}
}
/// <summary>
/// Handles the Click event of the btn_BrdColorPick Button.
/// Displays a ColorDialog to let the user select a new Color.
/// If the selected Color is different than the previous one,
/// the pnl_BrdColor panel is colored in the choosen Color, and
/// the OnActorBorderColorChanged method is invoked to fire a new
/// ActorBorderColorChanged event.
/// </summary>
/// <param name="sender">The object sending the event.</param>
/// <param name="e">The System.EventArgs describing the event.</param>
private void btn_BrdColorPick_Click(object sender, System.EventArgs e)
{
ColorDialog cd = new ColorDialog();
cd.AllowFullOpen=false;
cd.SolidColorOnly=true;
cd.AnyColor=false;
cd.Color=saveBrdColor;
DialogResult dr = cd.ShowDialog(this);
if(dr==DialogResult.OK)
{
Color newColor = cd.Color;
if(newColor!=saveBrdColor)
{
saveBrdColor = newColor;
this.pnl_BrdColor.BackColor=saveBrdColor;
if(!initializing)
OnActorBorderColorChanged(new ActorColorChangedEventArgs(saveBrdColor));
}
}
}
/// <summary>
/// Handles the TextChanged event of the tBox_Text text box. If the
/// new text is different than the previous one, the OnActorTextChanged
/// method is invoked to fire a new ActorTextChanged event.
/// </summary>
/// <param name="sender">The object sending the event.</param>
/// <param name="e">The System.EventArgs describing the event.</param>
private void tBox_Text_TextChanged(object sender, System.EventArgs e)
{
string ntxt = this.tBox_Text.Text;
if(ntxt!=saveText)
{
saveText = ntxt;
if(!initializing)
OnActorTextChanged(new ActorTextChangedEventArgs(saveText));
}
}

#endregion

#endregion

#region Protected Methods

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Custom Event Handlers

/// <summary>
/// Fires a new ActorLocationChanged event if any handler is registered.
/// </summary>
/// <param name="e">The ActorLocationChangedEventArgs describing the event.</param>
protected virtual void OnLocationChanged(ActorLocationChangedEventArgs e)
{ if(ActorLocationChanged!=null) ActorLocationChanged(this, e); }
/// <summary>
/// Fires a new ActorResize event if any handler is registered.
/// </summary>
/// <param name="e">The ActorResizeEventArgs describing the event.</param>
protected virtual void OnActorResized(ActorResizeEventArgs e)
{ if(ActorResized!=null) ActorResized(this, e); }
/// <summary>
/// Fires a new ActorFilledChanged event if any handler is registered.
/// </summary>
/// <param name="e">The ActorFilledChangedEventArgs describing the event.</param>
protected virtual void OnActorFilledChanged(ActorFilledChangedEventArgs e)
{ if(ActorFilledChanged!=null) ActorFilledChanged(this, e); }

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧