HelpProvider.GetHelpString メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HelpProvider.GetHelpString メソッドの意味・解説 

HelpProvider.GetHelpString メソッド

指定したコントロールポップアップ ヘルプ ウィンドウ内容返します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

<LocalizableAttribute(True)> _
Public Overridable Function
 GetHelpString ( _
    ctl As Control _
) As String
Dim instance As HelpProvider
Dim ctl As Control
Dim returnValue As String

returnValue = instance.GetHelpString(ctl)
[LocalizableAttribute(true)] 
public virtual string GetHelpString (
    Control ctl
)
[LocalizableAttribute(true)] 
public:
virtual String^ GetHelpString (
    Control^ ctl
)
/** @attribute LocalizableAttribute(true) */ 
public String GetHelpString (
    Control ctl
)
LocalizableAttribute(true) 
public function GetHelpString (
    ctl : Control
) : String

パラメータ

ctl

ヘルプ文字列取得対象となる Control

戻り値
このコントロール関連付けられたヘルプ文字列既定値null 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

KeyPressEventHandler クラスと KeyEventHandler クラス使用して入力フィルタする方法を示すコード例次に示します。この例はまた、GetHelpString メソッド処理方法示してます。この例は完結したコードです。これをプロジェクト追加して実行できます

Imports System.Drawing
Imports System.Windows.Forms
Imports System
Imports Microsoft.VisualBasic

Public Class Form1
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()

        InitializeComponent()
        AddHandlers()
        InitializeFormHelp()

    End Sub

    
    Friend WithEvents Label1 As
 System.Windows.Forms.Label
    Friend WithEvents Label2 As
 System.Windows.Forms.Label
    Friend WithEvents Label3 As
 System.Windows.Forms.Label
    Friend WithEvents withdrawal As
 System.Windows.Forms.TextBox
    Friend WithEvents deposit As
 System.Windows.Forms.TextBox
    Friend WithEvents ErrorProvider1 As
 System.Windows.Forms.ErrorProvider
    Friend WithEvents balance As
 System.Windows.Forms.Label
    Friend WithEvents HelpProvider1 As
 System.Windows.Forms.HelpProvider

   <System.Diagnostics.DebuggerStepThrough()> Private Sub
     InitializeComponent()
        Me.withdrawal = New System.Windows.Forms.TextBox
        Me.deposit = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.ErrorProvider1 = New System.Windows.Forms.ErrorProvider
        Me.balance = New System.Windows.Forms.Label
        Me.HelpProvider1 = New System.Windows.Forms.HelpProvider
        Me.SuspendLayout()
        
        Me.withdrawal.Location = New System.Drawing.Point(32,
 200)
        Me.withdrawal.Name = "withdrawal"
        Me.withdrawal.Size = New System.Drawing.Size(88,
 20)
        Me.withdrawal.TabIndex = 0
        Me.withdrawal.Text = ""
       
        Me.deposit.Location = New System.Drawing.Point(168,
 200)
        Me.deposit.Name = "deposit"
        Me.deposit.TabIndex = 1
        Me.deposit.Text = ""
       
        Me.Label1.Location = New System.Drawing.Point(56,
 88)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(96,
 24)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "Account Balance:"
       
        Me.Label2.Location = New System.Drawing.Point(168,
 168)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(96,
 24)
        Me.Label2.TabIndex = 4
        Me.Label2.Text = "Deposit:"
        
        Me.Label3.Location = New System.Drawing.Point(32,
 168)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(96,
 24)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "Withdrawal:"
        
        Me.ErrorProvider1.ContainerControl = Me
        
        Me.balance.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.balance.Location = New System.Drawing.Point(152,
 88)
        Me.balance.Name = "balance"
        Me.balance.TabIndex = 6
        Me.balance.Text = "345.65"
        Me.balance.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        
        Me.ClientSize = New System.Drawing.Size(292,
 266)
        Me.Controls.Add(Me.balance)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.deposit)
        Me.Controls.Add(Me.withdrawal)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub
 
   
    
    Private Sub AddHandlers()

        'Add the event-handler delegates to handle the KeyDown events.
        AddHandler deposit.KeyDown, _
            New KeyEventHandler(AddressOf ProcessEntry)
        AddHandler withdrawal.KeyDown, _
            New KeyEventHandler(AddressOf ProcessEntry)

        'Add the event-handler delegates to handled the KeyPress events.
        AddHandler deposit.KeyPress, _
            New KeyPressEventHandler(AddressOf
 CheckForDigits)
        AddHandler withdrawal.KeyPress, _
            New KeyPressEventHandler(AddressOf
 CheckForDigits)

    End Sub
    Private Sub InitializeFormHelp()

        ' Set the form's border to the FixedDialog style.
        Me.FormBorderStyle = FormBorderStyle.FixedDialog

        ' Remove the Maximize and Minimize buttons from the form.
        Me.MaximizeBox = False
        Me.MinimizeBox = False

        ' Add the Help button to the form.
        Me.HelpButton = True

        ' Set the Help string for the deposit textBox.
        HelpProvider1.SetHelpString(deposit, _
            "Enter an amount in the format xxx.xx"
 _
                & "and press Enter to deposit.")

        ' Set the Help string for the withdrawal textBox.
        HelpProvider1.SetHelpString(withdrawal, _
            "Enter an amount in the format xxx.xx"
 _
            & "and press Enter to withdraw.")

    End Sub

    Private Sub ProcessEntry(ByVal
 sender As Object, _
        ByVal e As KeyEventArgs)

        ' Cast the sender back to a TextBox.
        Dim textBoxSender As Control = CType(sender,
 TextBox)

        ' Set the error description to an empty string ().
        ErrorProvider1.SetError(textBoxSender, "")

        ' Declare the variable to hold the new balance.
        Dim newBalance As Double

        ' Wrap the code in a Try/Catch block to catch 
        ' errors that can occur when converting the string 
        ' to a double.

        Try
            If (e.KeyCode = Keys.Enter) Then

                ' Switch on the text box that received
                ' the KeyPress event. Convert the text to type double
,
                ' and compute the new balance.
                Select Case textBoxSender.Name
                    Case "withdrawal"
                        newBalance = Double.Parse(balance.Text)
 _
                            - Double.Parse(withdrawal.Text)
                        withdrawal.Text = ""
                    Case "deposit"
                        newBalance = Double.Parse(balance.Text)
 _
                            + Double.Parse(deposit.Text)
                        deposit.Text = ""
                End Select

                ' Check the value of new balance and set the
                ' Forecolor property accordingly.
                If (newBalance < 0) Then
                    balance.ForeColor = Color.Red
                Else
                    balance.ForeColor = Color.Black
                End If

                ' Set the text of the balance text box
                ' to the newBalance value.
                balance.Text = newBalance.ToString
            End If

        Catch ex As FormatException

            ' If a FormatException is thrown, set the
            ' error string to the HelpString message for 
            ' the control.
            ErrorProvider1.SetError(textBoxSender, _
                HelpProvider1.GetHelpString(textBoxSender))
        End Try
    End Sub


    Private Sub CheckForDigits(ByVal
 sender As Object, ByVal
 e _
        As KeyPressEventArgs)

        ' If the character is not a digit, period, or backspace then
        ' ignore it by setting the KeyPressEventArgs.Handled
        ' property to true.
        If Not (Char.IsDigit(e.KeyChar)
 _
            Or e.KeyChar = "."
 Or e.KeyChar = ChrW(Keys.Back)) Then
            e.Handled = True
        End If
    End Sub
   

    Public Shared Sub Main()
        Application.Run(New Form1)
    End Sub

End Class
   
using System.Drawing;
using System.Windows.Forms;
using System;
using Microsoft.VisualBasic;

public class Form1:
    System.Windows.Forms.Form

{

    public Form1() : base()
    {        

        InitializeComponent();
        AddHandlers();
        InitializeFormHelp();

    }

    internal System.Windows.Forms.Label Label1;
    internal System.Windows.Forms.Label Label2;
    internal System.Windows.Forms.Label Label3;
    internal System.Windows.Forms.TextBox withdrawal;
    internal System.Windows.Forms.TextBox deposit;
    internal System.Windows.Forms.ErrorProvider ErrorProvider1;
    internal System.Windows.Forms.Label balance;
    internal System.Windows.Forms.HelpProvider HelpProvider1;
    
[System.Diagnostics.DebuggerStepThrough]
    private void InitializeComponent()
    {
        this.withdrawal = new System.Windows.Forms.TextBox();
        this.deposit = new System.Windows.Forms.TextBox();
        this.Label1 = new System.Windows.Forms.Label();
        this.Label2 = new System.Windows.Forms.Label();
        this.Label3 = new System.Windows.Forms.Label();
        this.ErrorProvider1 = new         System.Windows.Forms.ErrorProvider();
        this.balance = new System.Windows.Forms.Label();
        this.HelpProvider1 = new         System.Windows.Forms.HelpProvider();
        this.SuspendLayout();
        
        this.withdrawal.Location = new System.Drawing.Point(32,
 200);
        this.withdrawal.Name = "withdrawal";
        this.withdrawal.Size = new System.Drawing.Size(88,
 20);
        this.withdrawal.TabIndex = 0;
        this.withdrawal.Text = "";
        
        this.deposit.Location = new System.Drawing.Point(168,
 200);
        this.deposit.Name = "deposit";
        this.deposit.TabIndex = 1;
        this.deposit.Text = "";
        
        this.Label1.Location = new System.Drawing.Point(56,
 88);
        this.Label1.Name = "Label1";
        this.Label1.Size = new System.Drawing.Size(96,
 24);
        this.Label1.TabIndex = 2;
        this.Label1.Text = "Account Balance:";
        
        this.Label2.Location = new System.Drawing.Point(168,
 168);
        this.Label2.Name = "Label2";
        this.Label2.Size = new System.Drawing.Size(96,
 24);
        this.Label2.TabIndex = 4;
        this.Label2.Text = "Deposit:";
        
        this.Label3.Location = new System.Drawing.Point(32,
 168);
        this.Label3.Name = "Label3";
        this.Label3.Size = new System.Drawing.Size(96,
 24);
        this.Label3.TabIndex = 5;
        this.Label3.Text = "Withdrawal:";
        
        this.ErrorProvider1.ContainerControl = this;
        
        this.balance.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
        this.balance.Location = new System.Drawing.Point(152,
 88);
        this.balance.Name = "balance";
        this.balance.TabIndex = 6;
        this.balance.Text = "345.65";
        this.balance.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
        
        this.ClientSize = new System.Drawing.Size(292,
 266);
        this.Controls.Add(this.balance);
        this.Controls.Add(this.Label3);
        this.Controls.Add(this.Label2);
        this.Controls.Add(this.Label1);
        this.Controls.Add(this.deposit);
        this.Controls.Add(this.withdrawal);
        this.Name = "Form1";
        this.Text = "Form1";
        this.ResumeLayout(false);

    }

    private void AddHandlers()
    {
        // Add the event-handler delegates to handled the KeyDown
        // events.
        deposit.KeyDown +=new KeyEventHandler(ProcessEntry); 
 
        withdrawal.KeyDown += new KeyEventHandler(ProcessEntry);

        // Add the event-handler delegates to handled the KeyPress 
        // events.
        deposit.KeyPress += new KeyPressEventHandler(CheckForDigits);
        withdrawal.KeyPress += 
            new KeyPressEventHandler(CheckForDigits);
    }

    private void InitializeFormHelp()
    {

        // Set the form's border to the FixedDialog style.
        this.FormBorderStyle = FormBorderStyle.FixedDialog;

        // Remove the Maximize and Minimize buttons from the form.
        this.MaximizeBox = false;
        this.MinimizeBox = false;

        // Add the Help button to the form.
        this.HelpButton = true;

        // Set the Help string for the deposit textBox.
        HelpProvider1.SetHelpString(deposit, 
            "Enter an amount in the format xxx.xx" +
            "and press Enter to deposit.");

        // Set the Help string for the withdrawal textBox.
        HelpProvider1.SetHelpString(withdrawal, 
            "Enter an amount in the format xxx.xx" +
            "and press Enter to withdraw.");

    }

    private void ProcessEntry(object sender,
 KeyEventArgs e)
    {

        // Cast the sender back to a TextBox.
        Control textBoxSender = (TextBox) sender;

        // Set the error description to an empty string ().
        ErrorProvider1.SetError(textBoxSender, "");

        // Declare the variable to hold the new balance.
        double newBalance = 0;

        // Wrap the code in a Try/Catch block to catch 
        // errors that can occur when converting the string 
        // to a double.

        try
        {
            if (e.KeyCode==Keys.Enter)

                // Switch on the text box that received
                // the KeyPress event. Convert the text to type double
,
                // and compute the new balance.
            {
                switch(textBoxSender.Name)
                {
                    case "withdrawal":
                        newBalance = Double.Parse(balance.Text) 
                            - Double.Parse(withdrawal.Text);
                        withdrawal.Text = "";
                        break;
                    case "deposit":
                        newBalance = Double.Parse(balance.Text) 
                            + Double.Parse(deposit.Text);
                        deposit.Text = "";
                        break;
                }

                // Check the value of new balance and set the
                // Forecolor property accordingly.
                if (newBalance < 0)
                {
                    balance.ForeColor = Color.Red;
                }
                else
                {
                    balance.ForeColor = Color.Black;
                }

                // Set the text of the balance text box
                // to the newBalance value.
                balance.Text = newBalance.ToString();
            }

        }
        catch(FormatException)
        {

            // If a FormatException is thrown, set the
            // error string to the HelpString message for 
            // the control.
            ErrorProvider1.SetError(textBoxSender, 
                HelpProvider1.GetHelpString(textBoxSender));
        }
    }


    private void CheckForDigits(object sender,
 KeyPressEventArgs e)
    {

        // If the character is not a digit, period, or backspace then
        // ignore it by setting the KeyPressEventArgs.Handled
        // property to true.
        if (!(Char.IsDigit(e.KeyChar) || e.KeyChar == '.' || 
            e.KeyChar == (char)(Keys.Back)))
        {
            e.Handled = true;
        }
    }
    

    public static void Main()
    {
        Application.Run(new Form1());
    }


}
#using <System.dll>
#using <Microsoft.VisualBasic.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System;
using namespace Microsoft::VisualBasic;
public ref class Form1: public
 System::Windows::Forms::Form
{
public:
   Form1()
      : Form()
   {
      InitializeComponent();
      AddHandlers();
      InitializeFormHelp();
   }


public private:
   System::Windows::Forms::Label ^ Label1;
   System::Windows::Forms::Label ^ Label2;
   System::Windows::Forms::Label ^ Label3;
   System::Windows::Forms::TextBox^ withdrawal;
   System::Windows::Forms::TextBox^ deposit;
   System::Windows::Forms::ErrorProvider^ ErrorProvider1;
   System::Windows::Forms::Label ^ balance;
   System::Windows::Forms::HelpProvider^ HelpProvider1;

private:

   [System::Diagnostics::DebuggerStepThrough]
   void InitializeComponent()
   {
      this->withdrawal = gcnew System::Windows::Forms::TextBox;
      this->deposit = gcnew System::Windows::Forms::TextBox;
      this->Label1 = gcnew System::Windows::Forms::Label;
      this->Label2 = gcnew System::Windows::Forms::Label;
      this->Label3 = gcnew System::Windows::Forms::Label;
      this->ErrorProvider1 = gcnew System::Windows::Forms::ErrorProvider;
      this->balance = gcnew System::Windows::Forms::Label;
      this->HelpProvider1 = gcnew System::Windows::Forms::HelpProvider;
      this->SuspendLayout();
      this->withdrawal->Location = System::Drawing::Point(
 32, 200 );
      this->withdrawal->Name = "withdrawal";
      this->withdrawal->Size = System::Drawing::Size( 88,
 20 );
      this->withdrawal->TabIndex = 0;
      this->withdrawal->Text = "";
      this->deposit->Location = System::Drawing::Point(
 168, 200 );
      this->deposit->Name = "deposit";
      this->deposit->TabIndex = 1;
      this->deposit->Text = "";
      this->Label1->Location = System::Drawing::Point( 56,
 88 );
      this->Label1->Name = "Label1";
      this->Label1->Size = System::Drawing::Size( 96, 24
 );
      this->Label1->TabIndex = 2;
      this->Label1->Text = "Account Balance:";
      this->Label2->Location = System::Drawing::Point( 168,
 168 );
      this->Label2->Name = "Label2";
      this->Label2->Size = System::Drawing::Size( 96, 24
 );
      this->Label2->TabIndex = 4;
      this->Label2->Text = "Deposit:";
      this->Label3->Location = System::Drawing::Point( 32,
 168 );
      this->Label3->Name = "Label3";
      this->Label3->Size = System::Drawing::Size( 96, 24
 );
      this->Label3->TabIndex = 5;
      this->Label3->Text = "Withdrawal:";
      this->ErrorProvider1->ContainerControl = this;
      this->balance->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
      this->balance->Location = System::Drawing::Point(
 152, 88 );
      this->balance->Name = "balance";
      this->balance->TabIndex = 6;
      this->balance->Text = "345.65";
      this->balance->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
      this->ClientSize = System::Drawing::Size( 292, 266 );
      this->Controls->Add( this->balance
 );
      this->Controls->Add( this->Label3
 );
      this->Controls->Add( this->Label2
 );
      this->Controls->Add( this->Label1
 );
      this->Controls->Add( this->deposit
 );
      this->Controls->Add( this->withdrawal
 );
      this->Name = "Form1";
      this->Text = "Form1";
      this->ResumeLayout( false );
   }

   void AddHandlers()
   {
      
      // Add the event-handler delegates to handled the KeyDown
      // events.
      deposit->KeyDown += gcnew KeyEventHandler( this, &Form1::ProcessEntry
 );
      withdrawal->KeyDown += gcnew KeyEventHandler( this, &Form1::ProcessEntry
 );
      
      // Add the event-handler delegates to handled the KeyPress 
      // events.
      deposit->KeyPress += gcnew KeyPressEventHandler( this,
 &Form1::CheckForDigits );
      withdrawal->KeyPress += gcnew KeyPressEventHandler( this,
 &Form1::CheckForDigits );
   }


   void InitializeFormHelp()
   {
      
      // Set the form's border to the FixedDialog style.
      this->FormBorderStyle = ::FormBorderStyle::FixedDialog;
      
      // Remove the Maximize and Minimize buttons from the form.
      this->MaximizeBox = false;
      this->MinimizeBox = false;
      
      // Add the Help button to the form.
      this->HelpButton = true;
      
      // Set the Help string for the deposit textBox.
      HelpProvider1->SetHelpString( deposit, "Enter an amount in
 the format xxx.xx"
      "and press Enter to deposit." );
      
      // Set the Help string for the withdrawal textBox.
      HelpProvider1->SetHelpString( withdrawal, "Enter an amount in
 the format xxx.xx"
      "and press Enter to withdraw." );
   }




   void ProcessEntry( Object^ sender, KeyEventArgs^ e )
   {
      
      // Cast the sender back to a TextBox.
      Control^ textBoxSender = dynamic_cast<TextBox^>(sender);
      
      // Set the error description to an empty string ().
      ErrorProvider1->SetError( textBoxSender, "" );
      
      // Declare the variable to hold the new balance.
      double newBalance = 0;
      
      // Wrap the code in a Try/Catch block to catch 
      // errors that can occur when converting the string 
      // to a double.
      try
      {
         if ( e->KeyCode == Keys::Enter )
         {
            if ( textBoxSender->Name->Equals( "withdrawal"
 ) )
            {
               newBalance = Double::Parse( balance->Text ) - Double::Parse( withdrawal->Text
 );
               withdrawal->Text = "";
            }
            else
            if ( textBoxSender->Name->Equals( "deposit"
 ) )
            {
               newBalance = Double::Parse( balance->Text ) + Double::Parse( deposit->Text
 );
               deposit->Text = "";
            }
            
            // Check the value of new balance and set the
            // Forecolor property accordingly.
            if ( newBalance < 0 )
            {
               balance->ForeColor = Color::Red;
            }
            else
            {
               balance->ForeColor = Color::Black;
            }
            
            // Set the text of the balance text box
            // to the newBalance value.
            balance->Text = newBalance.ToString();
         }
      }
      catch ( FormatException^ ) 
      {
         
         // If a FormatException is thrown, set the
         // error string to the HelpString message for 
         // the control.
         ErrorProvider1->SetError( textBoxSender, HelpProvider1->GetHelpString(
 textBoxSender ) );
      }

   }

   void CheckForDigits( Object^ /*sender*/, KeyPressEventArgs^
 e )
   {
      
      // If the character is not a digit, period, or backspace then
      // ignore it by setting the KeyPressEventArgs.Handled
      // property to true.
      if (  !(Char::IsDigit( e->KeyChar ) || e->KeyChar
 == '.' || e->KeyChar == (char)(Keys::Back)) )
      {
         e->Handled = true;
      }
   }

};

int main()
{
   Application::Run( gcnew Form1 );
}

import System.Drawing.*;
import System.Windows.Forms.*;
import System.*;
import Microsoft.VisualBasic.*;

public class Form1 extends System.Windows.Forms.Form
{
    public Form1()
    {
        InitializeComponent();
        AddHandlers();
        InitializeFormHelp();
    } //Form1 

    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.TextBox withdrawal;
    private System.Windows.Forms.TextBox deposit;
    private System.Windows.Forms.ErrorProvider errorProvider1;
    private System.Windows.Forms.Label balance;
    private System.Windows.Forms.HelpProvider helpProvider1;

    /** @attribute System.Diagnostics.DebuggerStepThrough()
     */
    private void InitializeComponent()
    {
        this.withdrawal = new System.Windows.Forms.TextBox();
        this.deposit = new System.Windows.Forms.TextBox();
        this.label1 = new System.Windows.Forms.Label();
        this.label2 = new System.Windows.Forms.Label();
        this.label3 = new System.Windows.Forms.Label();
        this.errorProvider1 = new System.Windows.Forms.ErrorProvider();
        this.balance = new System.Windows.Forms.Label();
        this.helpProvider1 = new System.Windows.Forms.HelpProvider();
        this.SuspendLayout();

        this.withdrawal.set_Location(new System.Drawing.Point(32,
 200));
        this.withdrawal.set_Name("withdrawal");
        this.withdrawal.set_Size(new System.Drawing.Size(88,
 20));
        this.withdrawal.set_TabIndex(0);
        this.withdrawal.set_Text("");

        this.deposit.set_Location(new System.Drawing.Point(168,
 200));
        this.deposit.set_Name("deposit");
        this.deposit.set_TabIndex(1);
        this.deposit.set_Text("");

        this.label1.set_Location(new System.Drawing.Point(56,
 88));
        this.label1.set_Name("Label1");
        this.label1.set_Size(new System.Drawing.Size(96,
 24));
        this.label1.set_TabIndex(2);
        this.label1.set_Text("Account Balance:");

        this.label2.set_Location(new System.Drawing.Point(168,
 168));
        this.label2.set_Name("Label2");
        this.label2.set_Size(new System.Drawing.Size(96,
 24));
        this.label2.set_TabIndex(4);
        this.label2.set_Text("Deposit:");

        this.label3.set_Location(new System.Drawing.Point(32,
 168));
        this.label3.set_Name("Label3");
        this.label3.set_Size(new System.Drawing.Size(96,
 24));
        this.label3.set_TabIndex(5);
        this.label3.set_Text("Withdrawal:");

        this.errorProvider1.set_ContainerControl(this);

        this.balance.set_BorderStyle(System.Windows.Forms.BorderStyle.Fixed3D);
        this.balance.set_Location(new System.Drawing.Point(152,
 88));
        this.balance.set_Name("balance");
        this.balance.set_TabIndex(6);
        this.balance.set_Text("345.65");
        this.balance.set_TextAlign(System.Drawing.ContentAlignment.MiddleLeft);

        this.set_ClientSize(new System.Drawing.Size(292,
 266));
        this.get_Controls().Add(this.balance);
        this.get_Controls().Add(this.label3);
        this.get_Controls().Add(this.label2);
        this.get_Controls().Add(this.label1);
        this.get_Controls().Add(this.deposit);
        this.get_Controls().Add(this.withdrawal);
        this.set_Name("Form1");
        this.set_Text("Form1");
        this.ResumeLayout(false);
    } //InitializeComponent

    private void AddHandlers()
    {
        // Add the event-handler delegates to handled the KeyDown
        // events.
        deposit.add_KeyDown(new KeyEventHandler(ProcessEntry));
        withdrawal.add_KeyDown(new KeyEventHandler(ProcessEntry));
        // Add the event-handler delegates to handled the KeyPress 
        // events.
        deposit.add_KeyPress(new KeyPressEventHandler(CheckForDigits));
        withdrawal.add_KeyPress(new KeyPressEventHandler(CheckForDigits));
    } //AddHandlers

    private void InitializeFormHelp()
    {
        // Set the form's border to the FixedDialog style.
        this.set_FormBorderStyle(get_FormBorderStyle().FixedDialog);
        // Remove the Maximize and Minimize buttons from the form.
        this.set_MaximizeBox(false);
        this.set_MinimizeBox(false);
        // Add the Help button to the form.
        this.set_HelpButton(true);
        // Set the Help string for the deposit textBox.
        helpProvider1.SetHelpString(deposit, 
            "Enter an amount in the format xxx.xx" 
            + "and press Enter to deposit.");
        // Set the Help string for the withdrawal textBox.
        helpProvider1.SetHelpString(withdrawal, 
            "Enter an amount in the format xxx.xx" 
            + "and press Enter to withdraw.");
    } //InitializeFormHelp

    private void ProcessEntry(Object sender,
 KeyEventArgs e)
    {
        // Cast the sender back to a TextBox.
        Control textBoxSender = (TextBox)sender;
        // Set the error description to an empty string ().
        errorProvider1.SetError(textBoxSender, "");
        // Declare the variable to hold the new balance.
        double newBalance = 0;
        // Wrap the code in a Try/Catch block to catch 
        // errors that can occur when converting the string 
        // to a double.
        try {
            if (e.get_KeyCode().Equals(Keys.Enter)) {
                // Switch on the text box that received
                // the KeyPress event. Convert the text to type double
,
                // and compute the new balance.
                if (textBoxSender.get_Name().Equals("withdrawal"))
 {
                    newBalance = System.Double.Parse(balance.get_Text()) 
                        - System.Double.Parse(withdrawal.get_Text());
                    withdrawal.set_Text("");
                }
                if (textBoxSender.get_Name().Equals("deposit"))
 {
                    newBalance = System.Double.Parse(balance.get_Text()) 
                        + System.Double.Parse(deposit.get_Text());
                    deposit.set_Text("");
                }
                // Check the value of new balance and set the
                // Forecolor property accordingly.
                if (newBalance < 0) {
                    balance.set_ForeColor(Color.get_Red());
                }
                else {
                    balance.set_ForeColor(Color.get_Black());
                }
                // Set the text of the balance text box
                // to the newBalance value.
                balance.set_Text(System.Convert.ToString(newBalance));
            }
        }
        catch (FormatException exp) {
            // If a FormatException is thrown, set the
            // error string to the HelpString message for 
            // the control.
            errorProvider1.SetError(textBoxSender, 
                helpProvider1.GetHelpString(textBoxSender));
        }
    } //ProcessEntry

    private void CheckForDigits(Object sender,
 KeyPressEventArgs e)
    {
        // If the character is not a digit, period, or backspace then
        // ignore it by setting the KeyPressEventArgs.Handled
        // property to true.
        if (!((Char.IsDigit(e.get_KeyChar()) || e.get_KeyChar()
 == '.' 
            || e.get_KeyChar() == (char)Keys.Back))) {
            e.set_Handled(true);
        }
    } //CheckForDigits

    public static void main(String[]
 args)
    {
        Application.Run(new Form1());
    } //main
} //Form1 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HelpProvider クラス
HelpProvider メンバ
System.Windows.Forms 名前空間
GetHelpString
GetHelpKeyword
GetShowHelp
SetHelpString
SetHelpKeyword



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

HelpProvider.GetHelpString メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HelpProvider.GetHelpString メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS