Reputation: 1518
I have a text box and it is in square form now I want to convert that square into oval shape i am using win forms application
can any one tell any idea about this
Upvotes: 1
Views: 8305
Reputation: 8126
You can use the SetWindowRgn
API Function to change the shape of a window.
This function - as you can see here - gets three arguments:
Handle
Property.You can subclass from TextBox
and create a Oval shaped TextBox by using this functions in OnHandleCreated
Method. The class can be something like this:
class OvalTextBox : TextBox
{
[DllImport("user32.dll")]
static extern int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool bRedraw);
[DllImport("gdi32.dll")]
static extern IntPtr CreateRoundRectRgn(int x1, int y1, int x2, int y2, int cx, int cy);
public OvalTextBox()
{
base.BorderStyle = System.Windows.Forms.BorderStyle.None;
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
SetWindowRgn(this.Handle, CreateRoundRectRgn(0, 0, this.Width, this.Height, 20, 20), true);
}
}
Upvotes: 5
Reputation: 48686
If you are doing this using Windows Forms, the only way is to create a new user control and inherit your control from TextBox. Then you must override the OnPaint method and implement your own drawing code.
IF its possible for you to use WPF though, its much easier. If you can make your application a WPF application, then all you need to do is drop a textbox onto your form and then put in a custom template for the shape.
Upvotes: 0
Reputation: 27913
Use the OvalShape control and put a textbox inside it. The textbox should have an an invisible.
Alternatively, create a customcontrol and override OnPaint so that it draws the oval with graphics.DrawElipse.
Upvotes: 1
Reputation: 6999
create ur class inherited by textbox, override OnPaint. Use your custom textbox in winforms.
Upvotes: 1