473,386 Members | 1,766 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,386 software developers and data experts.

Align an Image and Text within a WinForms RadioButton -- How to prevent text from overlapping image?


I have a set of radio buttons in a win form that each have an image
and text, like so:

O [image] [label]
O [image] [label]
O [image] [label]
O [image] [label]

How can I set it up so that the image is left aligned, next to the
radio button indicator, and the text is left aligned next to the
image?

I don't see any way to align the text so that it's aware of the image.

Thanks,

Sam

Nov 21 '05 #1
4 4073
Simple solution: make a label with the text and set its location to the radio
left + radio width + some padding.

Trickey solution: Calculate the image width and pad spaces to the radio text:

Dim g As Graphics = RadioButton1.CreateGraphics()
Dim ImageWidth As Integer = RadioButton1.Image.Width
Dim PadText As String = " "
Dim i As Integer = 0

While (True)

If g.MeasureString(PadText, RadioButton1.Font).Width * i >
ImageWidth Then Exit While

i += 1

RadioButton1.Text = PadText + RadioButton1.Text

End While

Maybe it won't work well with some fonts.

"Samuel R. Neff" wrote:

I have a set of radio buttons in a win form that each have an image
and text, like so:

O [image] [label]
O [image] [label]
O [image] [label]
O [image] [label]

How can I set it up so that the image is left aligned, next to the
radio button indicator, and the text is left aligned next to the
image?

I don't see any way to align the text so that it's aware of the image.

Thanks,

Sam

Nov 21 '05 #2
Simple solution: make a label with the text and set its location to the radio
left + radio width + some padding.

Trickey solution: Calculate the image width and pad spaces to the radio text:

Dim g As Graphics = RadioButton1.CreateGraphics()
Dim ImageWidth As Integer = RadioButton1.Image.Width
Dim PadText As String = " "
Dim i As Integer = 0

While (True)

If g.MeasureString(PadText, RadioButton1.Font).Width * i >
ImageWidth Then Exit While

i += 1

RadioButton1.Text = PadText + RadioButton1.Text

End While

Maybe it won't work well with some fonts.

"Samuel R. Neff" wrote:

I have a set of radio buttons in a win form that each have an image
and text, like so:

O [image] [label]
O [image] [label]
O [image] [label]
O [image] [label]

How can I set it up so that the image is left aligned, next to the
radio button indicator, and the text is left aligned next to the
image?

I don't see any way to align the text so that it's aware of the image.

Thanks,

Sam

Nov 21 '05 #3
The best way would be to create a usercontrol that combines the radiobutton,
image and label (and not use the radio button text).

Then use the control will have a property for the image and the text. When
you render the image, set it to autosize, and then set the label control to
have a left of the image.left+image.width + spacervalue.

Le MasterChief

"Samuel R. Neff" wrote:

I have a set of radio buttons in a win form that each have an image
and text, like so:

O [image] [label]
O [image] [label]
O [image] [label]
O [image] [label]

How can I set it up so that the image is left aligned, next to the
radio button indicator, and the text is left aligned next to the
image?

I don't see any way to align the text so that it's aware of the image.

Thanks,

Sam

Nov 21 '05 #4
The best way would be to create a usercontrol that combines the radiobutton,
image and label (and not use the radio button text).

Then use the control will have a property for the image and the text. When
you render the image, set it to autosize, and then set the label control to
have a left of the image.left+image.width + spacervalue.

Le MasterChief

"Samuel R. Neff" wrote:

I have a set of radio buttons in a win form that each have an image
and text, like so:

O [image] [label]
O [image] [label]
O [image] [label]
O [image] [label]

How can I set it up so that the image is left aligned, next to the
radio button indicator, and the text is left aligned next to the
image?

I don't see any way to align the text so that it's aware of the image.

Thanks,

Sam

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vinny Vinn | last post by:
Any ideas on how i can bold the text within a specific cell of a winforms datagrid?i have used DataGridColumnStyle for an entire column,however currently i need just the text of a specific cell to...
0
by: Samuel R. Neff | last post by:
I have a set of radio buttons in a win form that each have an image and text, like so: O O O O How can I set it up so that the image is left aligned, next to the radio button...
4
by: bkasmai | last post by:
On editing textboxes on a webform, when a user tab to a textbox, the text is highlighted or selected. Any accidental key press will remove the original text. This has proved a problem for the...
1
by: scott | last post by:
Hello, I'm trying to create the following effect: IMG text para- graph
10
tpgames
by: tpgames | last post by:
I want to use an image map, but I want the text that pops up when the mouse mouse overs the link to be larger. However, in an image map, that text is what's in the ALT tag, and doesn't appear to care...
2
by: ismailc | last post by:
Hi, I need help please! I want to vertical align the text within a text box. I can set the vertical align of the text box but not the text. My text box has a style property of: style...
3
by: smokinlabbit | last post by:
I'm trying to come up with a solution (but with no real direction to start with) where I'm trying to edit data in a td element of a table on the spot. What I want to do is when a td element...
0
by: Sirus86 | last post by:
problem with text and image.Text is overlaying or moving to below image. i design is very complex and i need to include a scroll within the design. this is what i have so far div id="content" ...
0
by: Sandeep Dhawan | last post by:
Hi, I have a requirement wherein I am trying to implement a functionality which will allow the user to preview a word doc, xls file or a pdf document over the web since our application . And the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.