I want to right-align numbers in a combobox. Since there is no TextAlign
property for the ComboBox, I tried the following code in a form containing a
default combobox.
'Declarations and two subs.
Dim miarr() As Long = {20000000000033 3, 33}
Dim moGraphics As Graphics = Me.CreateGraphi cs
Dim msngWidth As Single = 120
Private Sub MyForm_Load(ByV al sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim i As Integer
Me.ComboBox1.Dr opDownWidth = CInt(msngWidth) + 10
Me.ComboBox1.Dr awMode = System.Windows. Forms.DrawMode. OwnerDrawFixed
For i = 1 To 2
Me.ComboBox1.It ems.Add(i.ToStr ing)
Next
End Sub
Private Sub ComboBox1_DrawI tem(ByVal sender As Object, ByVal e As
System.Windows. Forms.DrawItemE ventArgs) Handles ComboBox1.DrawI tem
Try
Dim sngLen As Single =
moGraphics.Meas ureString(miarr (e.Index).ToStr ing, ComboBox1.Font) .Width
Debug.WriteLine ((sngLen).ToStr ing)
e.DrawBackgroun d()
e.Graphics.Draw String(miarr(e. Index).ToString , ComboBox1.Font,
System.Drawing. Brushes.Black, New _
RectangleF(msng Width - sngLen, e.Bounds.Top + 2, msngWidth,
e.Bounds.Height ))
Catch ex As Exception
End Try
End Sub
When I open this form and show the combo dropdown, I expected the numbers to
be right-aligned. Instead, they are off by about a half character. For the
values in the array, I get MeasureString values of 98.17106 and 16.26725
(default font).
Second observation, although DrawString() uses floating point numbers, it
seems that 16.40000 and 15.60000 produce identical positioned numbers; it
seems that the DrawString() method uses the Integer value when drawing the
characters.
This approach seems reasonable to me but the result is not satisfactory when
the numbers vary greatly in their digit count. What am I missing? Can
someone confirm this behaviour? 1 2329
Hi,
Use a stringformat for that. Here is an example.
Dim sf As New StringFormat
sf.Alignment = StringAlignment .Far
g.DrawString(mi arr(e.Index).To String, ComboBox1.Font, Brushes.Black,
RectangleF.op_I mplicit(e.Bound s), sf)
Ken
-------------------
"genojoe" <ge*****@discus sions.microsoft .com> wrote in message
news:68******** *************** ***********@mic rosoft.com... I want to right-align numbers in a combobox. Since there is no TextAlign property for the ComboBox, I tried the following code in a form containing a default combobox.
'Declarations and two subs. Dim miarr() As Long = {20000000000033 3, 33} Dim moGraphics As Graphics = Me.CreateGraphi cs Dim msngWidth As Single = 120
Private Sub MyForm_Load(ByV al sender As Object, ByVal e As System.EventArg s) Handles MyBase.Load Dim i As Integer Me.ComboBox1.Dr opDownWidth = CInt(msngWidth) + 10 Me.ComboBox1.Dr awMode = System.Windows. Forms.DrawMode. OwnerDrawFixed For i = 1 To 2 Me.ComboBox1.It ems.Add(i.ToStr ing) Next End Sub
Private Sub ComboBox1_DrawI tem(ByVal sender As Object, ByVal e As System.Windows. Forms.DrawItemE ventArgs) Handles ComboBox1.DrawI tem Try Dim sngLen As Single = moGraphics.Meas ureString(miarr (e.Index).ToStr ing, ComboBox1.Font) .Width Debug.WriteLine ((sngLen).ToStr ing) e.DrawBackgroun d() e.Graphics.Draw String(miarr(e. Index).ToString , ComboBox1.Font, System.Drawing. Brushes.Black, New _ RectangleF(msng Width - sngLen, e.Bounds.Top + 2, msngWidth, e.Bounds.Height )) Catch ex As Exception End Try End Sub
When I open this form and show the combo dropdown, I expected the numbers to be right-aligned. Instead, they are off by about a half character. For the values in the array, I get MeasureString values of 98.17106 and 16.26725 (default font).
Second observation, although DrawString() uses floating point numbers, it seems that 16.40000 and 15.60000 produce identical positioned numbers; it seems that the DrawString() method uses the Integer value when drawing the characters.
This approach seems reasonable to me but the result is not satisfactory when the numbers vary greatly in their digit count. What am I missing? Can someone confirm this behaviour? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bo Wisén |
last post by:
Hi,
A project in VB6 recently worked without any problems but now it's
complaining when I try to use 'Right$'. In immediate mode, when I'm typing
'print left$("123456",2)' I get the correct result '12'. When I type 'print
right$("123456",2) I expect the result '56' but all I get is an error 'type
declaration does not match declared data type'. And I can't find that I have
tried to declare 'right'. Can anyone explain what can cause this...
|
by: Ted Mencini |
last post by:
When I replaced older <IMG ALIGN=RIGHT ...> tags with a CSS definition
<IMG class=right ...>
xxx.css:
IMG.right { BORDER: 0; align: right }
I notice that the effect is NOT the same. While in the past the text was flowing smoothly around the picture
on the right side there is now a hard cut: Text, then picture below with white space on the left and finally
|
by: Dr. Richard E. Hawkins |
last post by:
I've googled around, and asked everyone I know, but I still can't find
any reference to anyone else having faced this particular IE bug with
floats.
I've put a page at http://dochawk.org/sample.html . This was made by
stripping out the google ads from the regular pages. It validates as
strict 4.01 at http://validator.w3.org. (The google ads drive it nuts!)
The main (right) column is made with alternating left and right floats
to...
|
by: Astra |
last post by:
Hi All
This has been bugging me for months and I just can't my finger on why it
won't work in Safari/FireFox (IE lets me off cos it's nice liek that).
In essence, the offending code is as follows:
<TD CLASS="NavBarHeaderCellB">
<!-- #include file="../incs/sprocs/fred.asp" -->
</TD>
|
by: Simon |
last post by:
Hi,
I have written a function to trim char *, but I have been told that my way
could be dangerous and that I should use memmove(...) instead.
but I am not sure why my code could be 'dangerous' or even why there could
be a problem.
here is the code
////////
| |
by: deanfamily11 |
last post by:
Ok, here's another problem I'm having. I've tried several different things,
but I just can't get anything to be right justified. Any thoughts?
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
|
by: ashkaan57 |
last post by:
Hi,
I have a page in a right-to-left language and I am trying to make some
bulleted lists using <ul>, but it puts the bullets to the left. Is
there any way I can set the bullets to be on the right:
..lists {
margin:2em 0 0 2em;
}
..lists ul {
|
by: tshad |
last post by:
I have a datagrid that I cannot get to right justify a money amount (which
is just a label). No matter what I do - it still right justifies it.
<asp:TemplateColumn Visible="true" itemStyle-Width="100px"
HeaderText="Amount Per Job" HeaderStyle-Font-Bold="true"
ItemStyle-VerticalAlign="middle" ItemStyle-HorizontalAlign="right" >
<itemtemplate>
<asp:Label ID="JobBoardPriceDisplay" style="text-align:right"
runat="server"/>
</itemtemplate>
|
by: Dio1080 |
last post by:
Ok, I need help on a for loop nested program using for loops, I'm trying to use a patten that goes like this:
123456
12345
1234
123
12
1
but when I try it, it goes like this:
123456
|
by: happyse27 |
last post by:
Hi All,
I wanted to align the text box for user registration but the code just wont budge... Kindly advise what is wrong?
Cheers...
Andrew
<HTML>
|
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...
| |
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |