Welcome to weblogs.com.pk Sign in | Join | Help

Adnan Siddiqi

Lets get technical

News



  • View Adnan Siddiqi's profile on LinkedIn
How to Handle Backspace in IE toolbar

Vist my blogs at http://kadnan.blogspot.com and http://weblogs.com.pk/kadnan

There is a wonderful article on codeproejct about using .net for making IE toolbar but this is very basic article and dont cover many things,one thing which several people miss is handling backspace,HOME and other keys in textbox placed on toolbar.i tried to add following code and it works for me,hope it will be helpful for others as well,if there is any mistake,kindly let me know,updated Helloworldbar.cs is given below.I have highlited the text which is required for handling Backspace,HOME,DEL and other keys.

using System;

using System.ComponentModel;

using System.Windows.Forms;

using BandObjectLib;

using System.Runtime.InteropServices;

namespace SampleBars

{

[Guid("AE07101B-46D4-4a98-AF68-0333EA26E113")]

[BandObject("Hello World Bar", BandObjectStyle.Horizontal | BandObjectStyle.ExplorerToolbar | BandObjectStyle.TaskbarToolBar, HelpText = "Shows bar that says hello.")]

public class HelloWorldBar : BandObject

{

private System.Windows.Forms.Button button1;

private System.ComponentModel.Container components = null;

//SendMessage from Win32 API

[DllImport ("user32.dll")]

public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, UInt32 wParam, Int32 lParam);

[DllImport("user32.dll")]

public static extern int TranslateMessage(ref MSG lpMsg);

[DllImport("user32", EntryPoint="DispatchMessage")]

static extern bool DispatchMessage(ref MSG msg);

 

public HelloWorldBar()

{

InitializeComponent();

//txtsearch is my textbox name,your textbox name could be different

txtSearch.GotFocus += new EventHandler(txtSearch_GotFocus);

              txtSearch.Focus();

}

private void txtSearch_GotFocus(object sender, EventArgs e)

              {

              this.OnGotFocus(e);

                }

public override int TranslateAcceleratorIO(ref MSG msg)

          {

             

              //const int WM_CHAR = 0x0102;

              TranslateMessage( ref msg );

              DispatchMessage( ref msg );

              return 0;

       }

protected override void Dispose( bool disposing )

{

if( disposing )

{

if( components != null )

components.Dispose();

}

base.Dispose( disposing );

}

#region Component Designer generated code

private void InitializeComponent()

{

this.button1 = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// button1

//

this.button1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)

| System.Windows.Forms.AnchorStyles.Left)

| System.Windows.Forms.AnchorStyles.Right);

this.button1.BackColor = System.Drawing.SystemColors.HotTrack;

this.button1.ForeColor = System.Drawing.SystemColors.Info;

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(150, 24);

this.button1.TabIndex = 0;

this.button1.Text = "Say Hello";

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// HelloWorldBar

//

this.Controls.AddRange(new System.Windows.Forms.Control[] {

this.button1});

this.MinSize = new System.Drawing.Size(150, 24);

this.Name = "HelloWorldBar";

this.Size = new System.Drawing.Size(150, 24);

this.Title = "Hello Bar";

this.ResumeLayout(false);

}

#endregion

private void button1_Click(object sender, System.EventArgs e)

{

MessageBox.Show("ZZZZZZ Hello, World!");

}

}

}

 

 

Posted: Monday, March 14, 2005 10:32 AM by kadnan

Comments

Andrew KawaTr said:

Thank you very much for this post. It works great except that you are missing a line of code in the TranslateAcceleratorIO function. The function needs to return a value. In this case 0.

public override int TranslateAcceleratorIO(ref MSG msg)
{
//const int WM_CHAR = 0x0102;
TranslateMessage( ref msg );
DispatchMessage( ref msg );
return 0;
}

Thanks again,
# March 14, 2005 8:34 PM

Adnan Siddiqi said:

Thanks
i had forgot to write here
its fixed now

-adnan
# March 14, 2005 11:48 PM

said:

Hi,

I'm trying to implement the toolbar in VB.NET, and still face the backspace issue. Could you help me out? Here's the VB.NET code using your instructions. Apparently I'm missing something?


<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function TranslateMessage(ByRef lpMsg As MSG) As Boolean
End Function

<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function DispatchMessage(ByRef lpMsg As MSG) As Int32
End Function


Public Overrides Function TranslateAcceleratorIO(ByRef msg As BandObjectLib.MSG) As Integer
TranslateMessage(msg)
DispatchMessage(msg)
Return 0
End Function




Thanks
# March 18, 2005 3:50 PM

TrackBack said:

# February 26, 2006 11:11 PM

kadnan said:

my code is not messing with it,i thinkyou would need to do setting for Hebrew so that you can input data in Unicode format.Sorry i have not worked on this
# February 28, 2006 10:15 AM
Anonymous comments are disabled