473,396 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Cannot change Font in custom textbox at runtime

2
I am using VB.NET VS2010

This seems like a trivial problem but I am unable to get past it. I have a very simple custom textbox class (full code below) that draws a rounded corner border around the textbox. This works as I expected. However, the font that appears in the textbox at runtime is not what I would like, so, I put a line of code in the Form that set it to a different font - no change. I tried setting the font using the properties window in design mode. It accepted the change there, but, at runtime the old default font was used. I am unable to control the font of the custom textbox either at runtime or design time. I did find that if I do not set ControlStyles.UserDraw to TRUE then the custom textbox behaves normally w/r/t font change but does not draw the custom border - but this defeats the purpose of making the custom textbox in the first place. I am sure I must be missing something obvious here. Help?

Expand|Select|Wrap|Line Numbers
  1. Imports System.Drawing.Drawing2D
  2. Public Class RoundedTextbox
  3.     Inherits TextBox
  4.     Public Sub New()
  5.         MyBase.New()
  6.         SetStyle(ControlStyles.UserPaint, True)
  7.         SetStyle(ControlStyles.AllPaintingInWmPaint, True)
  8.         BorderStyle = BorderStyle.FixedSingle
  9.     End Sub
  10.     Private Function ShrunkenBox() As RectangleF
  11.         Return New RectangleF(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1)
  12.     End Function
  13.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  14.         e.Graphics.FillRectangle(Brushes.White, ClientRectangle)
  15.         e.Graphics.DrawPath(Pens.LightGray, RoundCornerRectangle(ShrunkenBox))
  16.     End Sub
  17.     Private Function RoundCornerRectangle(ByVal Box As RectangleF) As Drawing2D.GraphicsPath
  18.         Dim Xcorner As Single = 6
  19.         Dim Ycorner As Single = 6
  20.         Dim result As New Drawing2D.GraphicsPath
  21.         '--- UL corner
  22.         result.AddArc(New RectangleF(Box.X, Box.Y, Xcorner, Ycorner), 180, 90)
  23.         '--- UR corner
  24.         result.AddArc(New RectangleF(Box.X + Box.Width - Xcorner, Box.Y, Xcorner, Ycorner), 270, 90)
  25.         '--- LR corner
  26.         result.AddArc(New RectangleF(Box.X + Box.Width - Xcorner, Box.Y + Box.Height - Ycorner, Xcorner, Ycorner), 0, 90)
  27.         '--- LL corner
  28.         result.AddArc(New RectangleF(Box.X, Box.Y + Box.Height - Ycorner, Xcorner, Ycorner), 90, 90)
  29.  
  30.         result.CloseFigure()
  31.         Return result
  32.     End Function
  33. End Class
  34.  
Feb 28 '13 #1
0 1196

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Rich | last post by:
Hi, I'm having problems with changing the Read Only properties. Running Winxp and i cannot get the "read only" to clear off a folder. The folder is one that i want to change the data in and it...
3
by: Ryan Joseph So | last post by:
Hi, I've been searching the web for custom textbox control that doesn't inherit from Windows textbox control but cannot find one. I've been trying to make my own custom textbox but I just dont...
1
by: Jeff N | last post by:
It it possible to change a button's or text box's font size during runtime? When I try to build my application with this code: this.ActiveControl.Font.Size = "8.25"; I get this error message:...
1
by: David Dvali | last post by:
Hello. I have one TextBox and one CheckBox on my web page, now when I click on the CheckBox I want to change font (depends on CheckBox state) of my TextBox wuth JavaScript. How can I do this? ...
4
by: Bernie Yaeger | last post by:
I'm building a custom textbox for numbers only (actually two of them - one for integers and one that allows currency entries, but let's discuss the integer only control). I'm having a problem...
4
by: Antuane | last post by:
i'm trying to create a custom textbox class, by simply creating a new class & inheriting from the textbox class. But i don't have a UI of this class. I.e., how can i set up the default text, color...
8
by: Radek Budař | last post by:
Hi all, i have trouble with changing text value of textbox on runtime. I use this control to display process information about sending e-mail per smtp. I use external component >>Imports...
2
by: AjitGoel | last post by:
Hi; I need to create a custom textbox control which will not allow a user to paste text from the clipboard. The user has to always type the text into the textbox. I tried searching on the...
3
by: rsdev | last post by:
Hi, I've successfully created a custom TextBox class based on 'TextBox', I have assigned a render method to encode the bound data into html encoded text. Like this; public class TextField :...
5
by: _Who | last post by:
I spent all day yesterday trying different things. Something has happened so I can't change font size. I have a table and in the first cell I have only text. I tried using the cell's Style...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.