PDA

View Full Version : نحوه استفاده از HelpRequested



amir_pro
چهارشنبه 21 آذر 1386, 21:29 عصر
سلام به دوستان
چه طور باید از این رویداد استفاده کرد. برای اینکه help button نشان داده بشه در فرم خاصیت مربوط به نشان دادن دکمه Minimize & Maximize را false کردم حالا می خوام ببینم نحوه کار با دکمه ؟ به چه صورت است.

dr_csharp
پنج شنبه 22 آذر 1386, 09:11 صبح
سلام به دوستان
چه طور باید از این رویداد استفاده کرد. برای اینکه help button نشان داده بشه در فرم خاصیت مربوط به نشان دادن دکمه Minimize & Maximize را false کردم حالا می خوام ببینم نحوه کار با دکمه ؟ به چه صورت است.

دوست عزیز اگر منظورتون دکمه ی help فرم هست :
کافیه عملیات مورد نظرتون برای Help رو در رویداد HelpButtonClicked فرمتون بنویسید .
رویداد دیگه ای که وجود داره HelpRequested هست که برای تمام کنترل های روی فرم جاری قابل انتخابه. بنابراین با استفاده از این رویداد شما میتونید نسبت به اینکه کاربر برای چه قسمتی تقاضای Help کرده آگاه بشید .

babak23
پنج شنبه 22 آذر 1386, 09:30 صبح
شما وقتی این مورد از فرم را true میکنید یک دگمه علامت سوال در بالای فرم و کناردکمه کلوز ظاهر میشه (البته به شرطی که خواص دکمه های مینیمم و ماکزییم false باشه )
شما میتوانید از این دکمه بعنوان راهنما در برنامه کاربردی خود استفاده کنید .برای این کار شما باید یک event handler برای HelpRequested ایجاد کنید (زمانی که کاربر روی دکمه مورد نظر کلیک میکند ).



public void CreateMyForm()
{
// Create a new instance of the form.
Form form1 = new Form();
// Create two buttons to use as the accept and cancel buttons.
Button button1 = new Button();
Button button2 = new Button();

// Set the text of button1 to "OK".
button1.Text = "OK";
// Set the position of the button on the form.
button1.Location = new Point(10, 10);
// Set the text of button2 to "Cancel".
button2.Text = "Cancel";
// Set the position of the button based on the location of button1.
button2.Location = new Point(button1.Left, button1.Height + button1.Top + 10);
// Set the caption bar text of the form.
form1.Text = "My Dialog Box";
// Display a help button on the form.
form1.HelpButton = true;

// Define the border style of the form to a dialog box.
form1.FormBorderStyle = FormBorderStyle.FixedDialog;
// Set the MaximizeBox to false to remove the maximize box.
form1.MaximizeBox = false;
// Set the MinimizeBox to false to remove the minimize box.
form1.MinimizeBox = false;
// Set the accept button of the form to button1.
form1.AcceptButton = button1;
// Set the cancel button of the form to button2.
form1.CancelButton = button2;
// Set the start position of the form to the center of the screen.
form1.StartPosition = FormStartPosition.CenterScreen;

// Add button1 to the form.
form1.Controls.Add(button1);
// Add button2 to the form.
form1.Controls.Add(button2);

// Display the form as a modal dialog box.
form1.ShowDialog();
}




این یه نمونه از HelpRequested



using System;
using System.Drawing;
using System.Windows.Forms;
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox addressTextBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox cityTextBox;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox stateTextBox;
private System.Windows.Forms.TextBox zipTextBox;
private System.Windows.Forms.Label helpLabel;
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
public Form1()
{
this.addressTextBox = new System.Windows.Forms.TextBox();
this.helpLabel = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.cityTextBox = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.stateTextBox = new System.Windows.Forms.TextBox();
this.zipTextBox = new System.Windows.Forms.TextBox();
// Help Label
this.helpLabel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.helpLabel.Location = new System.Drawing.Point(8, 80);
this.helpLabel.Size = new System.Drawing.Size(272, 72);
this.helpLabel.Text = "Click on any control to give it focus, and then " +
"press F1 to display help for that control. Alternately, you can " +
"click the help button at the top of the dialog and then click on a control.";
// Address Label
this.label2.Location = new System.Drawing.Point(16, 8);
this.label2.Size = new System.Drawing.Size(100, 16);
this.label2.Text = "Address:";
// Comma Label
this.label3.Location = new System.Drawing.Point(136, 56);
this.label3.Size = new System.Drawing.Size(16, 16);
this.label3.Text = ",";
// Address TextBox
this.addressTextBox.Location = new System.Drawing.Point(16, 24);
this.addressTextBox.Size = new System.Drawing.Size(264, 20);
this.addressTextBox.TabIndex = 0;
this.addressTextBox.Tag = "Enter the street address in this text box.";
this.addressTextBox.Text = "";
this.addressTextBox.HelpRequested += new System.Windows.Forms.HelpEventHandler(this.textBox _HelpRequested);
// City TextBox
this.cityTextBox.Location = new System.Drawing.Point(16, 48);
this.cityTextBox.Size = new System.Drawing.Size(120, 20);
this.cityTextBox.TabIndex = 3;
this.cityTextBox.Tag = "Enter the city here.";
this.cityTextBox.Text = "";
this.cityTextBox.HelpRequested += new System.Windows.Forms.HelpEventHandler(this.textBox _HelpRequested);
// State TextBox
this.stateTextBox.Location = new System.Drawing.Point(152, 48);
this.stateTextBox.MaxLength = 2;
this.stateTextBox.Size = new System.Drawing.Size(32, 20);
this.stateTextBox.TabIndex = 5;
this.stateTextBox.Tag = "Enter the state in this text box.";
this.stateTextBox.Text = "";
this.stateTextBox.HelpRequested += new System.Windows.Forms.HelpEventHandler(this.textBox _HelpRequested);
// Zip TextBox
this.zipTextBox.Location = new System.Drawing.Point(192, 48);
this.zipTextBox.Name = "zipTextBox";
this.zipTextBox.Size = new System.Drawing.Size(88, 20);
this.zipTextBox.TabIndex = 6;
this.zipTextBox.Tag = "Enter the zip code here.";
this.zipTextBox.Text = "";
this.zipTextBox.HelpRequested += new System.Windows.Forms.HelpEventHandler(this.textBox _HelpRequested);
// Set up how the form should be displayed and add the controls to the form.
this.ClientSize = new System.Drawing.Size(292, 160);
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.zipTextBox,
this.stateTextBox, this.label3, this.cityTextBox,
this.label2, this.helpLabel, this.addressTextBox});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.HelpButton = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Text = "Help Event Demonstration";
}
private void textBox_HelpRequested(object sender, System.Windows.Forms.HelpEventArgs hlpevent)
{
// This event is raised when the F1 key is pressed or the
// Help cursor is clicked on any of the address fields.
// The Help text for the field is in the control's
// Tag property. It is retrieved and displayed in the label.
Control requestingControl = (Control)sender;
helpLabel.Text = (string)requestingControl.Tag;
hlpevent.Handled = true;
}
}


جالب اینجاست که بعد از زدن دکمه hellp رو هر جا که کلیک کنید اطلاعاتی را در اون مورد بهت میده

babak23
پنج شنبه 22 آذر 1386, 09:41 صبح
اینهم یک نمونه برنامه