I am building a Windows form application and I have a text box for searching purposes.
I would like to put a search icon inside the text box, at the right or left
like this:
I would prefer at the right
I am asking about Windows forms not ASP.net or MVC
On the menu bar, choose Project > Properties. When the Project Designer appears, choose the Application tab. (Visual Basic)—In the Icon list, choose an icon (. ico) file.
Try using Application. EnableVisualStyles() . Make sure to call it before Application. Run() .
To add a button and a text box Verify that the document is open in the Visual Studio designer. From the Common Controls tab of the Toolbox, drag a TextBox control to the document.
Step 1: Create a windows form. Step 2: Drag the TextBox control from the ToolBox and Drop it on the windows form. You can place TextBox anywhere on the windows form according to your need. Step 3: After drag and drop you will go to the properties of the TextBox control to set the Text property of the TextBox.
You can use a Panel
, a TextBox
and a PictureBox
.
The TextBox must be placed in a Panel so you can't write over your search picture.
You can create a new UserControl which will do the required job. You have to extend the TextBox class for that. Look at the code below:
public class IconTextBox : System.Windows.Forms.TextBox
{
public IconTextBox() : base() { SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true); this.Multiline = true; }
public System.Drawing.Bitmap BitmapImage
{
set;
get;
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
System.Drawing.Image img = BitmapImage as System.Drawing.Image;
e.Graphics.DrawImage(img, new System.Drawing.Point(this.Width - (img.Width), 0));
}
}
And in the OnPaint method you can specify the image. Also you can extend this to have a custom property which can be the image path. Your choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With