Is it possible to have dynamic size on a textbox? If the context is only one
line then the box is only one line, but if the context is 10 lines then the
box adjust to this?
/Per W. 10 1628
Set the Multiline property to true.
--
HTH,
Kevin Spencer
Microsoft MVP
Ministry of Software Development http://unclechutney.blogspot.com
Any experience you can walk away from
is a good one.
"Per W." <pe**@tiscali.nowrote in message
news:ej**********@troll.powertech.no...
Is it possible to have dynamic size on a textbox? If the context is only
one line then the box is only one line, but if the context is 10 lines
then the box adjust to this?
/Per W.
"Kevin Spencer" <sp**@uce.govskrev i melding
news:eo**************@TK2MSFTNGP04.phx.gbl...
Set the Multiline property to true.
i have done that, but i want the height of the box to adjust to the number
of lines in the box, i dont want to use scroll bars. Maybe i can count the
number of lines and set the height after how many lines there is.
/Per W.
On Fri, 17 Nov 2006 22:41:46 +0100, Per W. wrote:
"Kevin Spencer" <sp**@uce.govskrev i melding
news:eo**************@TK2MSFTNGP04.phx.gbl...
>Set the Multiline property to true.
i have done that, but i want the height of the box to adjust to the number
of lines in the box, i dont want to use scroll bars. Maybe i can count the
number of lines and set the height after how many lines there is.
/Per W.
Well, the textbox is actually a native component, so the only way I can
think of is to use the SendMessageLong API call with something like
EM_GETLINECOUNT, and use that to calculate the height you need the control
to be.
A bit messy, but while Win32API is being used for control rendering we have
very little choice in the matter.
Cheers,
Gadget
You can use the System.Drawing.Graphics.MeasureString() method to measure
the rectangle that the text will occupy. The method takes a Font as an
argument, and an overload that takes a SizeF, so that, for example, if you
want to limit the width, you can pass a SizeFto the method. See: http://msdn2.microsoft.com/en-us/lib...urestring.aspx
--
HTH,
Kevin Spencer
Microsoft MVP
Ministry of Software Development http://unclechutney.blogspot.com
Any experience you can walk away from
is a good one.
"Per W." <pe**@tiscali.nowrote in message
news:ej**********@troll.powertech.no...
>
"Kevin Spencer" <sp**@uce.govskrev i melding
news:eo**************@TK2MSFTNGP04.phx.gbl...
>Set the Multiline property to true.
i have done that, but i want the height of the box to adjust to the number
of lines in the box, i dont want to use scroll bars. Maybe i can count the
number of lines and set the height after how many lines there is.
/Per W.
As I just posted (later than yours), I have successfully used the
System.Drawing.Graphics.MeasureString method to to this. Of course, using
the Win32 API is always available, and I use it occasionally for tasks that
aren't available through Managed code.
--
HTH,
Kevin Spencer
Microsoft MVP
Ministry of Software Development http://unclechutney.blogspot.com
Any experience you can walk away from
is a good one.
"Gadget" <ga****@sobell.netwrote in message
news:11*****************************@40tude.net...
On Fri, 17 Nov 2006 22:41:46 +0100, Per W. wrote:
>"Kevin Spencer" <sp**@uce.govskrev i melding news:eo**************@TK2MSFTNGP04.phx.gbl...
>>Set the Multiline property to true.
i have done that, but i want the height of the box to adjust to the number of lines in the box, i dont want to use scroll bars. Maybe i can count the number of lines and set the height after how many lines there is.
/Per W.
Well, the textbox is actually a native component, so the only way I can
think of is to use the SendMessageLong API call with something like
EM_GETLINECOUNT, and use that to calculate the height you need the control
to be.
A bit messy, but while Win32API is being used for control rendering we
have
very little choice in the matter.
Cheers,
Gadget
"Gadget" <ga****@sobell.netskrev i melding
news:11*****************************@40tude.net...
On Fri, 17 Nov 2006 22:41:46 +0100, Per W. wrote:
>"Kevin Spencer" <sp**@uce.govskrev i melding news:eo**************@TK2MSFTNGP04.phx.gbl...
>>Set the Multiline property to true.
i have done that, but i want the height of the box to adjust to the number of lines in the box, i dont want to use scroll bars. Maybe i can count the number of lines and set the height after how many lines there is.
/Per W.
Well, the textbox is actually a native component, so the only way I can
think of is to use the SendMessageLong API call with something like
EM_GETLINECOUNT, and use that to calculate the height you need the control
to be.
A bit messy, but while Win32API is being used for control rendering we
have
very little choice in the matter.
Thanx, but do you now about som step by step to do this? All i can find is
only working on VB 6.0 and earlier.
/Per W.
On Sat, 18 Nov 2006 07:49:40 -0500, Kevin Spencer wrote:
As I just posted (later than yours), I have successfully used the
System.Drawing.Graphics.MeasureString method to to this. Of course, using
the Win32 API is always available, and I use it occasionally for tasks that
aren't available through Managed code.
I'd be very intersted to see this working. I know that I tried to use this
some time ago for the same requirements as Per, but I found the
MeasureString results never seemed to match what the textbox rendered, and
I had to add cludges to multiply heights by 1.05, etc, and still often
ended up with the bottom line missing (or a blank line appended).
It would be a very useful feature to have available on a listbox, so
perhaps someone should knock up a custom control? :)
Cheers,
Gadget
Hi Gadget,
The following example code is abbreviated from some code I use to build a
table grid. I removed the extraneous looping through rows, etc, and left in
the basic measuring technique:
// 96 bpi bitmap (Same dpi as screen) used to get a System.Drawing.Graphics
instance for measuring.
private Bitmap GraphicsHelper;
protected void GetGraphicsHelper()
{
GraphicsHelper =
(Bitmap)global::DsiGlobal.FormControls.Properties. Resources.GraphicsHelper;
}
public void LoadTables()
{
int cellHeight = 0; // Row Height variable
int i;
SizeF textSize = new SizeF();
SizeF cellSize = new SizeF();
string cellValue;
// System.Drawing.StringFormat deals with String Formatting rules when drawn
StringFormat format = new StringFormat();
format.FormatFlags = StringFormatFlags.LineLimit;
format.Trimming = StringTrimming.EllipsisWord;
using (Graphics graphics = Graphics.FromImage(GraphicsHelper))
{
// Uses the column width of a column, and a Maximum column height
cellSize = new SizeF(TableManager.Columns[i].Width, (float)maxRowHeight);
// the text to be displayed
cellValue = Convert.ToString(row[i]);
// returns a SizeF only large enough to hold the text, constrained by
width
textSize = graphics.MeasureString(cellValue, this.Font.GetFont(),
cellSize, format);
}
}
See http://msdn2.microsoft.com/en-gb/library/957webty.aspx for more
information about this overload of the System.Drawing.Graphics.MeasureString
method. The size passed represents the maximum size. The height will be
truncated to fit the text.
--
HTH,
Kevin Spencer
Microsoft MVP
Ministry of Software Development http://unclechutney.blogspot.com
Any experience you can walk away from
is a good one.
"Gadget" <ga****@sobell.netwrote in message
news:1e*****************************@40tude.net...
On Sat, 18 Nov 2006 07:49:40 -0500, Kevin Spencer wrote:
>As I just posted (later than yours), I have successfully used the System.Drawing.Graphics.MeasureString method to to this. Of course, using the Win32 API is always available, and I use it occasionally for tasks that aren't available through Managed code.
I'd be very intersted to see this working. I know that I tried to use this
some time ago for the same requirements as Per, but I found the
MeasureString results never seemed to match what the textbox rendered, and
I had to add cludges to multiply heights by 1.05, etc, and still often
ended up with the bottom line missing (or a blank line appended).
It would be a very useful feature to have available on a listbox, so
perhaps someone should knock up a custom control? :)
Cheers,
Gadget
On Mon, 20 Nov 2006 09:19:54 -0500, Kevin Spencer wrote:
// 96 bpi bitmap (Same dpi as screen) used to get a System.Drawing.Graphics
instance for measuring.
private Bitmap GraphicsHelper;
protected void GetGraphicsHelper()
{
GraphicsHelper =
(Bitmap)global::DsiGlobal.FormControls.Properties. Resources.GraphicsHelper;
}
public void LoadTables()
{
int cellHeight = 0; // Row Height variable
int i;
SizeF textSize = new SizeF();
SizeF cellSize = new SizeF();
string cellValue;
// System.Drawing.StringFormat deals with String Formatting rules when drawn
StringFormat format = new StringFormat();
format.FormatFlags = StringFormatFlags.LineLimit;
format.Trimming = StringTrimming.EllipsisWord;
using (Graphics graphics = Graphics.FromImage(GraphicsHelper))
{
// Uses the column width of a column, and a Maximum column height
cellSize = new SizeF(TableManager.Columns[i].Width, (float)maxRowHeight);
// the text to be displayed
cellValue = Convert.ToString(row[i]);
// returns a SizeF only large enough to hold the text, constrained by
width
textSize = graphics.MeasureString(cellValue, this.Font.GetFont(),
cellSize, format);
}
}
Thanks Kevin, It'll be interesting to have an experiment with this,
although I'm not convinced this will work as well with a TextBox as they
have padding margins that seem to be designed to screw-up any auto-sizing
code :)
I think most grid controls, particularly third party ones, avoid using the
native textbox components in any way and draw directly to a graphics
context, avoiding all these issues.
Of course, now Per reveals he actually wants this for a web page, the whole
discussion rather loses its reason for existence :)
Cheers,
Gadget
If you were still working with a TextBox, you would use the ClientSize
rectangle of the TextBox to get the width, and include some padding around
the Text in your calculations.
--
HTH,
Kevin Spencer
Microsoft MVP
Ministry of Software Development http://unclechutney.blogspot.com
Never trust a dunderhead with a blunderbuss.
"Gadget" <ga****@sobell.netwrote in message
news:1o****************************@40tude.net...
On Mon, 20 Nov 2006 09:19:54 -0500, Kevin Spencer wrote:
>// 96 bpi bitmap (Same dpi as screen) used to get a System.Drawing.Graphics instance for measuring. private Bitmap GraphicsHelper;
protected void GetGraphicsHelper() { GraphicsHelper = (Bitmap)global::DsiGlobal.FormControls.Properties .Resources.GraphicsHelper; }
public void LoadTables() { int cellHeight = 0; // Row Height variable int i; SizeF textSize = new SizeF(); SizeF cellSize = new SizeF(); string cellValue;
// System.Drawing.StringFormat deals with String Formatting rules when drawn StringFormat format = new StringFormat(); format.FormatFlags = StringFormatFlags.LineLimit; format.Trimming = StringTrimming.EllipsisWord; using (Graphics graphics = Graphics.FromImage(GraphicsHelper)) { // Uses the column width of a column, and a Maximum column height cellSize = new SizeF(TableManager.Columns[i].Width, (float)maxRowHeight); // the text to be displayed cellValue = Convert.ToString(row[i]); // returns a SizeF only large enough to hold the text, constrained by width textSize = graphics.MeasureString(cellValue, this.Font.GetFont(), cellSize, format); } }
Thanks Kevin, It'll be interesting to have an experiment with this,
although I'm not convinced this will work as well with a TextBox as they
have padding margins that seem to be designed to screw-up any auto-sizing
code :)
I think most grid controls, particularly third party ones, avoid using the
native textbox components in any way and draw directly to a graphics
context, avoiding all these issues.
Of course, now Per reveals he actually wants this for a web page, the
whole
discussion rather loses its reason for existence :)
Cheers,
Gadget
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gidi |
last post by:
Hi,
For the last week, i'm looking for a way to make a TextBox always write in
English (No matter what the OS default language is).
i asked here few times but the answers i got didn't help me. i...
|
by: Visual Systems AB \(Martin Arvidsson\) |
last post by:
Hi!
Can any one point me in direction of modify a TextBox control.
What i want to do is to add a button, like the ComboBox have. with my own
bitmap
and execute an Event when clicked.
I...
|
by: Dennis |
last post by:
I have a simple form with one button and one text box. In the Form, I create
an array list to track the events by adding a descriptive string item to the
arraylist in each event. I first Click on...
|
by: Brad Rogers |
last post by:
All,
Being immersed in vb.net and trying CSharp after almost a year I forgot the
differences. I like vb fixing the uppercase/lowercase names and seeming to
be more flexible to code entry.
...
|
by: CharlesA |
last post by:
Hi folks,
I'm using ASP.net 1.1 with C#
I've got this kind of thing going
<div class="row">
<label class="col1">Rm Name</label>
<asp:textbox id="txtRM" runat="server" cssclass="col2"...
|
by: Filipe Marcelino |
last post by:
Hi,
I'm trying to create a textbox inheriting from the standard textbox. I
would like to:
1. repaint the textbox border;
2. define a color for that border;
Till now I made this:
|
by: garyusenet |
last post by:
I have a multiline textbox.
The size of the text box should be 75 characters wide, and 5 lines in
height like this: -
<---75 characters-->
<---75 characters-->
<---75 characters-->
<---75...
|
by: Jacob Donajkowski |
last post by:
Once the user logs in I want to have the users switch from the Roster
View to the Profile View and enter their profile infomation and save
it. Then the next time they login and go to the Profile...
|
by: sjickells |
last post by:
Hi
I am having a problem using asp:TextBox's in a transparent table.
I have a background image on the page and a table in the middle of the
page. I have set the background colour of the table...
|
by: rakeshnair |
last post by:
i wrote a code in jsp to create dynamic table..the problem is i need data base connection when cursor moves from one cell to other...
eg...when i enter product id in the first cell, the product name...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |