|
Hello frnds,
Here is the issue.
My application should check whether or not the space provided for displaying a string (in different languages) is sufficient. I have Width and Height of the space provided in pixels and font type, font size of the string.
So how can i solve this? I can think of 2 ways.
1. Get width of each character and sum up to get the width needed in pixels. For this i need to know width of each character in pixels? Is there a way i can find this?
2. There should be a predefined API to get the width of the string in pixels. If yes what is that API?
Any help would be highly appreciated.
Thanks,
Hari krishna.
|
|
|
|
|
Not sure if this will work for you, but have you tried using MeasureString? You can try something like this:
Dim g As Graphics
Dim size As New SizeF
Dim myFont As New Font("Arial",8) 'Just as an example, you can replace it with whatever font/size you are using
g=CreateGraphics()
size=g.MeasureString(myString,myFont)
g.Dispose
Don't forget to import System.Drawing.Graphics
Dominick
|
|
|
|
|
Dominick,
Thanks for the prompt response. Is there a way i can acheive this in VB?
Thanks,
Hari krishna.
|
|
|
|
|
That was VB, VB.Net... what are you working with if not VB.net?
|
|
|
|
|
The example I gave was VB.NET
|
|
|
|
|
Ok, I'm confused because the example presented to you earlier was in VB.Net, code done and everything. All you had to do was just tweak it a bit to suit your needs. But you didn't... you asked him how to use it...
|
|
|
|
|
If you're talking about legacy VB, then you can use the GdipMeasureString function in the gdiplus.dll file
|
|
|
|
|
What I would do personally is just make another label or textbox with autosize set to true and turn its visibility off, store whatever string in there and use check its height and width property to see how big the string is..
That is assuming I understood the question correctly.
|
|
|
|
|
Hello All,
Thanks for the replies.. I really appreciate your effort.
I did some research and finally found out the way to find Height and Width of the character (any language). I am posting this because i could see only questions on this and i didn't find any reply with the exact solution.
1. Get the handle to the desktop.
2. Get the device context using this desktop handle.
3. Create the font using CreateFont for particular font type.
4. Use selectobject to assign this font type to the device context.
5. GetTextExtentPoint32 to get the height and width of the character you want.
I followed the above steps and was able to get the results as expected.
Please excuse me if i am wrong somewhere..
Thanks,
Hari krishna.
|
|
|
|
|
Hello,
I have used a localized form for Turkish. However I am not able display any Turkish characters in the listview. It displays a questionmark (?) instead of the turkish characters in some entries in the listview.
How can I solve this problem?
Thank you.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
you can use encoding which support different format
try following
str="string with turkish character"<br />
Encoding.UTF8.GetString(Encoding.Default.GetBytes(str))
hope this helps
|
|
|
|
|
I have 2 tables in MS Access
Username is set as the primary key that relates both the tables
I want to insert fields into my second table from my form along with the Username from the first table
how can i do this?
can anybody help me on this?
thanks in advance
|
|
|
|
|
can u be more specific regarding ur need ?
=> U want to insert record in master table and then in detail table ? OR
=> U already have record in master table and insert in detail table ?
|
|
|
|
|
i need to insert in the detail table
master table and detail table has Username field unique
from the logon screen, username has to be fetched and stored in the detailed table and from another form few fields has to be inserted in the same table
in simple, i want to insert fields from two screens into a single(detailed) table
modified on Tuesday, February 3, 2009 8:16 AM
|
|
|
|
|
A Username is a very bad field to use as a key. Use an auto-incrementing number instead.
There are, literally, thousands of examples of how to do this on the web. All you have to do is search[^].
|
|
|
|
|
Dave Kreskowiak wrote: Use an auto-incrementing number instead.
Isn't that considered bad practice?
Can't recall any examples right now but I seem to remember that you could have a number of difficulty's with those.
|
|
|
|
|
Using an auto-increment isn't nearly as bad as using a string and duplicating that time and time again. At least, with a 32-bit integer, you've got a couple billion records to work with and it's a guaranteed 4-bytes per record. How long would that string be??
|
|
|
|
|
I agree that its (a lot) better than using a string, I just thought it was considered bad practice to use a auto-increment.
But I guess in his case it couldn't do much harm.
|
|
|
|
|
Why would you consider using auto-increment keys as a bad practice
|
|
|
|
|
well as I said in my first post I don't recall the exact problem with it but do remember have some problems with it, and I try to avoid using them as much as I can now.
|
|
|
|
|
One problem is that if you use auto increment keys only, you may have logically duplicate data. But on the upside, updating the user defined data is a whole lot easier and faster (no cascaded updates etc.).
These are the reasons I always use (at least) double keys on every table and I haven't experienced any problems. However, if you remember the scenario at some point, I would be very happy to hear it
|
|
|
|
|
somebody help me to solve this problem
|
|
|
|
|
Dave answered your question.
You'll need to "remember" (store in variable) the username from the first form and then when user entered data one the second you'll have to use a INSERT or UPDATE sql statement (depending on whether or not it is a new user or existing).
If you search the web you'll find thousands of examples.
|
|
|
|
|
I have two tables
first one contains username and password as fields and the second table contains username,date,project and hours field
the user has to logon from the first form with username and password which leads to a second form where date,project nd hours are entered
when the submit button is clicked on this form, username,date,project and hours has to be entered into the second table
from the logon form, username has to be fetched and stored in the second table and from the current form few fields has to be inserted in the same table when submit is clicked
|
|
|
|
|
Repeating your question isn't going to change the answer.
Like I said you'll have to store the username in a variable that can be accessed by the second form.
Then in the submit click event you'll have to use a INSERT sql statement to insert the correct data into the second table (provided that the username is present in the first table)
On a side note you might want to take Dave's advice and change your key to a numeric key (auto increment).
Don't expect us to write this for you.
This is very basic and we are happy to help where needed but you need to program it. If you get stuck on a particular part you can then come back here and ask a more specific question, because the way your asking it now is asking us to write your whole program. If you want that go to rentacoder.com.
|
|
|
|