473,799 Members | 2,900 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4108
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.Cr eateGraphics()
Dim ImageWidth As Integer = RadioButton1.Im age.Width
Dim PadText As String = " "
Dim i As Integer = 0

While (True)

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

i += 1

RadioButton1.Te xt = PadText + RadioButton1.Te xt

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.Cr eateGraphics()
Dim ImageWidth As Integer = RadioButton1.Im age.Width
Dim PadText As String = " "
Dim i As Integer = 0

While (True)

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

i += 1

RadioButton1.Te xt = PadText + RadioButton1.Te xt

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+imag e.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+imag e.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
4687
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 be bold? Thanks
0
337
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 indicator, and the text is left aligned next to the
4
2109
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 users. Is it possible to set a textbox so that the text is not selected when a user tabs to that textbox? Any help on this will be appreciated. BK
1
2412
by: scott | last post by:
Hello, I'm trying to create the following effect: IMG text para- graph
10
3582
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 what the text size says in the CSS. Is there a cure for this? (Outside of a separate text only area of links for navigation, I'm already planning on doing this.) Thanks! (ps. I did try to research this, and no one mentions text size, just all the...
2
9948
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 ="height : 20px; border : 1px solid #CCCCCC;" but my text is to high on top in the text box
3
1941
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 containing text is clicked on, the text within this td becomes an input text field. The data within the text field, upon submission, be it via a button or enter or whatever, will be the new data within the td element after submission. Is there a viable...
0
1249
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" > <table background="images/Layer-7.png" width="677" height="311" alt="content" class="pngimg" /> <tr> <td> Lorem ipsum dolor sit amet, consectetur adipiscing elit. In a est magna, vel tincidunt nulla. Maecenas ligula enim, pretium id porta...
0
1078
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 user should be able to zoom and search within the document being previewed. To do this, I was thinking of converting the document into an image since it is easy to view an image using the browser. But the issue, is that I also need to allow the...
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10485
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10231
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9073
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.