Home
Winforms
Interview FAQs

FAQs of level

System.Windows.Forms.MessageBox.Show("Hello, Windows Forms");
Yes, you can. Then the class belongs to global namespace which has no name. For commercial products, naturally, you would not want global namespace.
Set the TextBox.PasswordChar property to the character that you want to use for password -
textBox1.PasswordChar = '\u25CF';
First set the ContextMenu property of the TextBox to a dummy, empty ContextMenu instance. This will prevent the default context menu from showing. Then, override the ProcessCmdKey method as follows in a TextBox derived class -

protected override bool ProcessCmdKey( ref Message msg, Keys keyData ){
if ( keyData == (Keys.Control | Keys.V) )
return true;
else
return base.ProcessCmdKey( ref msg, keyData );
}

Use the CharacterCasing property of the TextBox.

textBox1.CharacterCasing = CharacterCasing.Upper;
textBox2.CharacterCasing = CharacterCasing.Lower;

You can prevent the beep when the enter key is pressed in a TextBox by deriving the TextBox and overriding OnKeyPress -

public class CustomTextBox : TextBox {
protected override void OnKeyPress( KeyPressEventArgs e )
{
if ( e.KeyChar == (char) 13 )
e.Handled = true;
else
base.OnKeyPress( e );
} }

Get a Graphics object for the button and use its MeasureString method to compute the width you need.

using ( Graphics g = button1.CreateGraphics() )
float w = g.MeasureString( button1.Text, button1.Font ).Width;
button1.Width = (int) w + 12; // 12 is for the margins

You can use the Button.Image property to add an image to a button face. Use the Button.ImageAlign (and possibly Button.TextAlign) to layout your button face.

You can also implement custom drawing on a button face.

Subclass Button and add a custom Paint event handler that does you custom drawing.

public class CustomButton : Button
{
public CustomButton()
{
Paint += new PaintEventHandler( ButtonPaint );
}

private void ButtonPaint( object sender, PaintEventArgs e )
{
Pen pen = new Pen( Color.Red );
pen.Width = 8;
e.Graphics.DrawLine( pen, 7, 4, 7, Height - 4 );
pen.Width = 1;
e.Graphics.DrawEllipse( pen, Width - 16 , 6, 8, 8 );
}
}

Use the Button's public method PerformClick().
PreviousDisplaying 3 of 7Next
1 2 3 4 5 6 7
Need Help? Contact Us.

Log in

*
*

Forgot password?

*

New User

*
*
*
*