473,888 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need Your Advice on "DrawString on Panel with AutoScroll"

I'm trying to use the DrawText() method to draw some very long string
text on the Panel with AutoScroll enabled. However, for some unknown
reasons, I could not trigger the ScrollBar to show up.

Here is the simplicied section of drawing code:

private void panel_Paint(obj ect sender,
System.Windows. Forms.PaintEven tArgs e)
{
panel.AutoScrol l = true;
Font font = new System.Drawing. Font( "Arial", 18.0f );
SolidBrush brush = new System.Drawing. SolidBrush( Color.Black );
string s = "this is a very very long long long string string.";
e.Graphics.Draw String( s, font, brush, 0, 0);
}

The text did draw on the panel. However, this long string was
truncated without triggering the scrollBar.

What's wrong with my code?

Thank you for your help!
Nov 16 '05 #1
1 9370
Hi,

If you are going to draw manually you will need to make the needed
calculations, this include split the string as needed. you do not need to do
this I think.

I had to do something similar in a pocketPC application, I need to
dynamically insert text in a Panel, this is done by inserting Label controls
as needed (simpler than draw the string manually) being the trick
calculating the size of the label . if the panel has the autoScrool ( the CF
does not has it so another solution is needed) it will handle the scrolling
without further asistance.

The code below will show you how to do this , please note that this was
programmed to run on a Pockect PC app. maybe there is a simpler way to
calculate the size required for an a string in the desktop framework.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Label text = new Label();
text.Text = row["Text"].ToString();
text.Top = topY;
text.Width = InteriorItemsPa nel.Width - 10;

SizeF size = this.MeasureStr ingExtend(g, text.Text, text.Font,
text.Width);
text.Height = Convert.ToInt32 ( size.Height+1 );

panel.Controls. Add ( text);

public SizeF MeasureStringEx tend(Graphics g, string text, Font font, int
desWidth)
{
string tempString = text;
string workString = "";
int npos = 1;
int sp_pos = 0;
int line = 0;
int nWidth = 0;

//get original size
SizeF size = g.MeasureString (text, font);

if (size.Width > desWidth)
{
while(tempStrin g.Length > 0)
{
//Check for the last lane
if (npos > tempString.Leng th)
{
line++;
break;
}
workString = tempString.Subs tring(0, npos);
//get the current width
nWidth = (int)g.MeasureS tring(workStrin g, font).Width;
//check if we've got out of the destWidth
if (nWidth > desWidth)
{
//try to find a space
sp_pos = workString.Last IndexOf(" ");
if (sp_pos > 0)
{
//cut out the wrap lane we've found
tempString = tempString.Subs tring((sp_pos + 1), tempString.Leng th -
(sp_pos + 1));
line++;
npos = 0;
}
else //no space
{
tempString = tempString.Subs tring(npos, tempString.Leng th - npos);
line++;
npos = 0;
}
}
npos++;
}
return new SizeF(desWidth, (line*size.Heig ht)) ;
}
else
return size;

}

"John" <jo***********@ hotmail.com> wrote in message
news:d7******** *************** ***@posting.goo gle.com...
I'm trying to use the DrawText() method to draw some very long string
text on the Panel with AutoScroll enabled. However, for some unknown
reasons, I could not trigger the ScrollBar to show up.

Here is the simplicied section of drawing code:

private void panel_Paint(obj ect sender,
System.Windows. Forms.PaintEven tArgs e)
{
panel.AutoScrol l = true;
Font font = new System.Drawing. Font( "Arial", 18.0f );
SolidBrush brush = new System.Drawing. SolidBrush( Color.Black );
string s = "this is a very very long long long string string.";
e.Graphics.Draw String( s, font, brush, 0, 0);
}

The text did draw on the panel. However, this long string was
truncated without triggering the scrollBar.

What's wrong with my code?

Thank you for your help!

Nov 16 '05 #2

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

Similar topics

0
1223
by: adolf garlic | last post by:
Currently we have an app (asp.net 1.1) that has a dynamic content client scripted treeview which will allow the display of reporting services reports in the right hand part of the screen. My problem is this: Is there a neat way of displaying the reports from reporting services other than using frames? (which everyone seems to hate). I could almost do with some kind of 'placeholder' control that I can just
0
1482
by: VB Programmer | last post by:
I wanted to access some properties of a panel control that is on a different form. So, I went to the (Declarations) section of my main form (the form with the panel) and changed the panel (called "panKnob") from "Friend WithEvents" to "Public Shared WithEvents" so that I could access it from another class (i.e. frmMain.panKnob.Visible=True") I get this build error: "The variable 'panKnob' is either undeclared or was never assigned." ...
1
2451
by: Edward | last post by:
When designing a page in VS2003, in the toolbox, tab HTML there was a "Grid Layout Panel". I cannot find this control in VS2005. Where can I find the control now?
3
2296
by: Tom Bianchi | last post by:
Hi, I have a Panel with the AutoScroll property set to True and many TextBoxes into it, with only some of them positioned in the visible portion of the panel. Is there a Panel event that I can handle when I tab from textbox to textbox and the panel has to scroll *automatically* from the current position to bring the focused control into view ? I know it is possible to use the Enter event of each textbox, but I must execute a time...
1
12097
by: TheSteph | last post by:
Hi ! I would like to create a UserControl that act as a « Collapsible Panel ». So I have a UserControl with two panels : a "Header panel" at the top, and a "Container Area Panel" docked to fill the remaining client area of the
1
4062
by: Jefferds.A | last post by:
Hi, I'm putting together a little database of individuals categorized by family. I have two lists, one that contains family names and one that contains individuals' names. When you click on a link in the first list, it generates from a mysql database all the people associated with that family. When you click on an individual's name, it displays biographical information. The catch is, for space, I've put these lists in little boxes...
5
1679
by: Curious | last post by:
I installed a service program. It contained executables in the form of .exe and .dll files. And the service was started automatically after the install. Then, I UN-installed the program, but the service didn't get cleared from the "Service" panel. How can I delete this "service" from the "Services" panel?
0
9800
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
11181
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
10886
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
10439
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
9597
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...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3252
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.