473,815 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Label control questions; avoiding cut-off text

C R
I have a label inside of a form. The form is maximized to fill the
entire screen. I would like the label to take up 40% of the width of the
screen, and 70% of the height, regardless of monitor size or resolution.
How can I do this?

Also, if I use a certain font & font size, how can I avoid getting any
half-lines of text, where you just see the cut-off tops or bottoms of
the letters?

Thanks for any help!

CR

*** Sent via Developersdex http://www.developersdex.com ***
Dec 28 '05 #1
9 8698
C R wrote:
I have a label inside of a form. The form is maximized to fill the
entire screen. I would like the label to take up 40% of the width of the
screen, and 70% of the height, regardless of monitor size or resolution.
How can I do this?

Also, if I use a certain font & font size, how can I avoid getting any
half-lines of text, where you just see the cut-off tops or bottoms of
the letters?

Thanks for any help!

CR

*** Sent via Developersdex http://www.developersdex.com ***


Am I missing something or isn't it as simple as after you resize the
form to full screen, get the forms width and height then multiply by
your 40% and 70%?

chris
Dec 28 '05 #2
"C R" <sh********@gma il.com> schrieb:
I have a label inside of a form. The form is maximized to fill the
entire screen. I would like the label to take up 40% of the width of the
screen, and 70% of the height, regardless of monitor size or resolution.
\\\
With Screen.PrimaryS creen.WorkingAr ea
Me.Size = New Size(CInt(.Widt h * 0.7), CInt(.Height * 0.7))
End With
///
Also, if I use a certain font & font size, how can I avoid getting any
half-lines of text, where you just see the cut-off tops or bottoms of
the letters?

Check out the label control's 'AutoSize' property and controls' 'Dock' and
'Anchor' properties.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 28 '05 #3
In order to have full control of the text being displayed, you're going
to have to do custom drawing on a panel, usercontrol, or form. Below
is an example of doing custom drawing on a form meeting your
requirements.

Regards,

Colin Neller
www.colinneller.com/blog

----

Public Class Form1

Private s As String

Private Sub Form1_Load(ByVa l sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim sb As New System.Text.Str ingBuilder
For i As Integer = 0 To 1000
sb.Append("This text repeats a lot. ")
Next
s = sb.ToString

With Me
.SetStyle(Contr olStyles.AllPai ntingInWmPaint, True)
.SetStyle(Contr olStyles.Resize Redraw, True)
.SetStyle(Contr olStyles.Optimi zedDoubleBuffer , True)
End With
End Sub

Private Sub Form1_Paint(ByV al sender As Object, _
ByVal e As System.Windows. Forms.PaintEven tArgs) Handles Me.Paint
Dim w As Single = CSng(Me.Width * 0.4)
Dim h As Single = CSng(Me.Height * 0.7)

Using format As New StringFormat, _
brush As New SolidBrush(Me.F oreColor)

With format
.Alignment = StringAlignment .Far
.FormatFlags = StringFormatFla gs.LineLimit
.LineAlignment = StringAlignment .Center
.Trimming = StringTrimming. EllipsisWord
End With

Dim r As New RectangleF(0, 0, w, h)

With e.Graphics
.DrawString(s, Me.Font, brush, r, format)
End With
End Using
End Sub

End Class

Dec 28 '05 #4
C R
Colin,

Thanks so much for your help!

DrawString was just what I needed to get the level of control I want.

C R


*** Sent via Developersdex http://www.developersdex.com ***
Jan 4 '06 #5

Colin,

When I do the DrawStrings in the form's Load event, they work, but then
the form gets blanked out. Subsequent Drawstrings based on mouse events
work fine. Any idea why, and how to get around this?

shishudas


*** Sent via Developersdex http://www.developersdex.com ***
Jan 4 '06 #6
Sure! As in my example, put any code that is used to paint in the "Paint"
event of the control that you are painting onto. No painting should occur
in the "Load" event. The paint event is called every time windows notifies
your form that it needs to repaint its self - just what you need.

--
Colin Neller
http://www.colinneller.com/blog
"Shishu Das" <sh********@gma il.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..

Colin,

When I do the DrawStrings in the form's Load event, they work, but then
the form gets blanked out. Subsequent Drawstrings based on mouse events
work fine. Any idea why, and how to get around this?

shishudas


*** Sent via Developersdex http://www.developersdex.com ***

Jan 4 '06 #7

Well, when I put the Drawstrings in Paint, they work, but then the form
gets blanked out (same as happens in Load). I can't figure out why.
Perhaps it does my Drawstrings, but then "re-paints" the blank form. Is
there an After-Paint event or something like that? This is a bit
confusing...

shishudas

*** Sent via Developersdex http://www.developersdex.com ***
Jan 5 '06 #8
Post a simple example of what you are trying to do and I'll have a look.

--
Colin Neller
http://www.colinneller.com/blog
"Shishu Das" <sh********@gma il.com> wrote in message
news:uW******** ******@TK2MSFTN GP12.phx.gbl...

Well, when I put the Drawstrings in Paint, they work, but then the form
gets blanked out (same as happens in Load). I can't figure out why.
Perhaps it does my Drawstrings, but then "re-paints" the blank form. Is
there an After-Paint event or something like that? This is a bit
confusing...

shishudas

Jan 5 '06 #9
Ah, I solved it in the process of creating a simple example. The culprit
was:

Me.SetStyle(Con trolStyles.Doub leBuffer, True)

Maybe you can explain why...

shishudas


*** Sent via Developersdex http://www.developersdex.com ***
Jan 5 '06 #10

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

Similar topics

7
4516
by: Rab | last post by:
hi i need to programmatically change the caption of a label that is linked to another control (i.e. textbox, combobox). it's for a generic function where i only know the textbox/combobox name but not the name of the label that is linked to the textbox/combobox. example sub: public sub ReSetCaption()
3
4159
by: Peter Verburgh | last post by:
Is there an easy way to capture the keypress - keydown events from a LABEL control ? Standard the control doesn't handle these events. The label control inherits from the control class , and this class has the keypress - keydown event handlers. So i believe this must be possible ? k/Regards,
2
3997
by: John Bowman | last post by:
Hello, I need to concatonate 2 strings and insert padding spaces in between them. The number of padding spaces needs to be calculated such that I can place the entire resultant string into a label control and have it appear as if the 1st string is left justified & the 2nd string is right justified. How can I properly calculate the number of needed spaces when I'm using the label control's default MS Sans Serif font? OR does anyone have a...
2
2429
by: John Holmes | last post by:
I would like to turn on a label control in javascript with the onfocus event of another control by setting the Visible property to true. When I try and reference this label control it says "Microsoft JScript runtime error: 'document.Form1.lblSigGrantor' is null or not an object". I wrote a loop and iterated through the elements for the form and this control doesn't show up. Code listed below, please help. Thanks, John Holmes
0
1189
by: Darren Li | last post by:
Hi, I use .net Label web control in my web app., which will generate <Span> tag WITH style attributes (width;height) on client side browser. I have 2 questions: 1. If the client side browser is not MSIE; the IIS generate the <Span> tag WITHOUT Style attributes. So the web page format looks wiered. 2. I tired the label control in new VS.NET 2005 beta. It generates the
31
7255
by: jcrouse | last post by:
Is there a quick and easy way to change the color of a label controls border from the default black to white? Thank you, John
0
1697
by: Mark | last post by:
I want to create a user control inherited from a TextBox with an associated label (let's call it a LabelTextBox). The trick is that I want the control to inherit from TextBox and have all of its properties available rather than the default properties of the user control. I also do not want to have to expose the Textbox properties one by one in a user control. I have already previously created this control using Delphi and I have...
1
3461
by: Alex | last post by:
Hi all - I'm trying to put a tooltip on a label in csharp... I found an example that says to add some code to the InitializeComponent() method, but that's in the .Designer.cs file - which says to not edit it. Is there a different way to go about it that is designer friendly? ....in InitializeComponent():
1
9085
by: Jason Huang | last post by:
Hi, In my C# windows form, I have a Label which has many words in it. So I'm thinking using the ScrollBar so I can scroll up and down to see the whole words. Would someone tell me how? Thanks for help. Jason
25
2483
by: Marco | last post by:
Hi everyone. I've been trying to move some small applications written in vb.net 2003 to vb.net 2005 express just for testing purposes. I have noticed so far that the applications seem to run much slower in the 2005 version. Especially when it comes to nested loops. I haven't done much testing so it might just be this one computer but I was curious to know if anyone else has experienced these kind of problems when moving to the 2005...
0
9735
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
9610
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
10672
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
10427
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
10143
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
9225
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
5570
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...
1
4358
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
3886
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.