all groups > dotnet windows forms > january 2006 >
You're in the

dotnet windows forms

group:

[C#] Is there a way to prevent a Button to getting the focus?


RE: [C#] Is there a way to prevent a Button to getting the focus? AMercer
1/13/2006 3:52:01 PM
dotnet windows forms:
[quoted text, click to view]

Set the button's TabStop property to False.

Re: [C#] Is there a way to prevent a Button to getting the focus? Norman Yuan
1/13/2006 4:55:15 PM
You simply need to set TabIndex and/or TabStop property of a control (in
Properties Window, or menu "View->Tab Order").

[quoted text, click to view]

[C#] Is there a way to prevent a Button to getting the focus? EricL
1/13/2006 11:56:17 PM
C# question:

Is there a way to prevent a button from getting the focus and from being
painted with a rectangle of small dots when clicking on it?

Specifically, I have a form with 2 TextBox and a Button: say I am in the
first TextBox and the Button is the next control in the form.

What do I have to do so that tabbing out of the first TextBox skips the
Button over and sets focus to the second Textbox?

Thanks for help.

Eric

Re: [C#] Is there a way to prevent a Button to getting the focus? EricL
1/14/2006 9:47:10 AM
Yes, thank you. I had tried that.

But that's not enough.

I'd also like to avoid seeing the small dots signifying focus, appear on the
button when I click on it.

Is that possible?

Thanks.

[quoted text, click to view]

Re: [C#] Is there a way to prevent a Button to getting the focus? Morten Wennevik
1/14/2006 12:15:22 PM
Hi Eric,

You can handle the Click event and pass the focus somewhere else.

this.GetNextControl(button2, false).Focus();

It needs a tiny bit of coding to get it to work intelligently, but you will always get the dottet rectangle whenever you hold the mouse button down.

If you don't want the rectangle whatsoever I suggest you create a dummy button out of a label, panel or even Control.

[quoted text, click to view]



--
Happy coding!
Re: [C#] Is there a way to prevent a Button to getting the focus? Dave Leach
1/17/2006 12:11:02 PM
Eric,

You could use interoperablity services to get at some features available in
the user32.dll. Look at the following code for some ideas. The public
methods below allow you to control the appearance of focus effects on
controls.

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

using namespace DllImports
{
public class User32DllImports
{
public User32DllImports()
{}

protected const int WM_CHANGEUISTATE = 0x00000127;
protected const int UIS_SET = 1;
protected const int UIS_CLEAR = 2;

protected const short UISF_HIDEFOCUS = 0x0001;
protected const short UISF_HIDEACCEL = 0x0002;
protected const short UISF_ACTIVE = 0x0004;

[DllImport( "user32.dll" )]
public extern static int SendMessage( IntPtr hWnd, int wMsg, int
wParam, int lParam );

public static void MakeAcceleratorsVisible( Control c )
{
SendMessage( c.Handle, WM_CHANGEUISTATE, MAKELONG(UIS_CLEAR,
UISF_HIDEACCEL), 0 );
}

public static void MakeAcceleratorsInvisible( Control c )
{
SendMessage( c.Handle, WM_CHANGEUISTATE, MAKELONG(UIS_SET,
UISF_HIDEACCEL), 0 );
}

public static void MakeFocusVisible( Control c )
{
SendMessage( c.Handle, WM_CHANGEUISTATE, MAKELONG(UIS_CLEAR,
UISF_HIDEFOCUS), 0 );
}

public static void MakeFocusInvisible( Control c )
{
SendMessage( c.Handle, WM_CHANGEUISTATE, MAKELONG(UIS_SET,
UISF_HIDEFOCUS), 0 );
}

public static void MakeActiveVisible( Control c )
{
SendMessage( c.Handle, WM_CHANGEUISTATE, MAKELONG(UIS_SET,
UISF_ACTIVE), 0 );
}

public static void MakeActiveInvisible( Control c )
{
SendMessage( c.Handle, WM_CHANGEUISTATE, MAKELONG(UIS_CLEAR,
UISF_ACTIVE), 0 );
}

private static short LOWORD( int dw )
{
short loWord = 0;
ushort andResult = (ushort)(dw & 0x00007FFF);
ushort mask = 0x8000;
if ( (dw & 0x8000) != 0 )
{
loWord = (short)( mask | andResult );
}
else
{
loWord = (short)andResult;
}
return loWord;
}

private static int MAKELONG( int wLow, int wHigh )
{
int low = (int)LOWORD( wLow );
short high = LOWORD( wHigh );
int product = 0x00010000 * (int)high;
int makeLong = (int)( low | product );
return makeLong;
}
}
}

Hope that helps,
Dave

[quoted text, click to view]
Re: [C#] Is there a way to prevent a Button to getting the focus? EricL
1/19/2006 12:28:27 AM
Dave,

Thank you very much.

Eric

[quoted text, click to view]

AddThis Social Bookmark Button