473,657 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create a string of n pixel width...

Since I have no control over a treeview's scroll bars (i'm drawing icons
and text to the right of the treenodes) I've decided to just add some
special text to the end of my tree node text which I will then strip out
when it comes to drawing the treenode into the treeview...

Anyway I know there is a way to get the pixel length of a string that
already exists, but is there a good way to create a string of characters
that are a certain length? Should I just have a function that loops
adding 'x' until it's a certain length? Since this will only be run
when a node is created or when a node's special properties change I'm
just planning on doing this - unless any of you know of a better solution.

Thanks,
Benny
Nov 27 '05 #1
2 2465
Some methods used for graphics/drawing automatically wrap text a new line
when given the bounds of the Text as a rectangle. I don't know if this is in
CLI but it is in the managed DirectX libraries, so you should be able to do
this somehow. By the way, you'll need a method to tell you the length of the
String with a specified Font- unless you're using a fixed-width font,
different characters will have different (visual) lengths.
Nov 27 '05 #2
Graphics.Measur eString( string text, Font font )

does the measuring of the string automatically for me... What I wanted
was to create a string that was x length automatically.. . What I ended
up doing was to loop adding a character to my string until MeasureString
returned a value >= the value I wanted. This seems to be working fine.

~Benny

--- Message from Reuben
Some methods used for graphics/drawing
automatically wrap text a new line
when given the bounds of the Text as a
rectangle. I don't know if this is in
CLI but it is in the managed DirectX
libraries, so you should be able to do
this somehow. By the way, you'll need a
method to tell you the length of the
String with a specified Font- unless
you're using a fixed-width font,
different characters will have different
(visual) lengths.

Nov 28 '05 #3

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

Similar topics

1
4912
by: Veerle | last post by:
Hi, I have 2 div blocks with each div taking up half of the page width. So in the CSS they both have width: 50%. See http://home.scarlet.be/~vv991306/leftright.html In Mozilla Firefox and Opera, depending on the width of the browser window, sometimes there is a 1 pixel gap between the 2 div blocks. In Internet Explorer, this is never the case.
7
3592
by: TomHL | last post by:
hello, - I have a Bitmap Object named: bmp1 - I already have the numerical values of:red,blue and green colors + I have the X and Y cordinates. How do I set the pixel value via safe code on the bmp1 object? (the pixel location based on the X & Y values and it's color based on the red,blue and green values the I already have)
3
2389
by: Sangeeta | last post by:
Hi, I have a datagrid where columns are of some fixed pixel size. If any column text increases the width of column, the plan is to truncate it till its pixel width becomes less than the coloumn width. Is there a way to find the size of a char in pixel given the font name and size. I have tried using System.Drawing.Graphics object, but the width attribute of the returned fSize object does not return value in pixels. I am including the...
5
1579
by: Alex Nitulescu | last post by:
Hi. Because I'm a beginner in creating controls, I spent more than two *&^#$ hours to create this "login" as a custom control and to make it work properly: _________________________________________________________________________________________________________ Imports System.ComponentModel Imports System.Web.UI Imports System.Web.UI.WebControls <Description("Provides a login component"), DefaultProperty(""),
5
7367
by: Lance | last post by:
I need to create a Drawing.Bitmap from an array of integer values. My current technique creates a bitmap that eventually becomes corrupt (i.e., the bitmap's pixels change to a different color after a while). Can somebody please tell me what I'm doing wrong? Here is a sample: Public Shared Function CreateBitmapFromArray( _ ByVal width As Integer, _ ByVal height As Integer, _ ByVal pixelFormat As Drawing.Imaging.PixelFormat, _
11
786
by: cc | last post by:
Hi, From a C# application am I writing some text in a Word.Table, in a Cell of the Table to be more precise. The cell has a certain width and any string written in the cell will cover one or more lines in the cell depending on its length. In other words, it will use wordwrapping Now, I have to determine the amount of lines that the text will take when
3
2789
by: Bart Van der Donck | last post by:
Hello, I'm having a hard time trying to configure printed output that consists of multiple pages. The idea is the following: <div style=" border: 1px solid blue; position: absolute; top: 20px; left: 20px;
7
43892
by: carterweb | last post by:
This is how I do it now. 1. Determine the dimensions of the rectangle. 2. Set a my font size to a fixed maximum size. 3. Apply the font my string and measure the string using the graphics object. 4. If string size is less than the size of the rectangle, we are done.
5
4169
by: WT | last post by:
I am trying to crete a gif file with transparent backcolor on the fly but it seems that GDI refuses to do this. I am using samples from Bob Powell but it doesn't seem to work. First create a Bitmap public Bitmap MakeImage(string Text, SizeF Sf) { int width = (int)(Sf.Width)+2;
0
8305
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
8726
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8603
tracyyun
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...
0
7320
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
6163
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
5632
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();...
0
4151
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
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.