473,414 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Text Box Question

Re displaying text in a multi-line text box:

Is it possible to have a margin on the left hand side, or on both
sides, so the text doesn't come right up to the border(s)?

Many thanks.
--
Regards,
Patrick.
Nov 15 '05 #1
10 4793
Yes it is. This should do it for you:

[DllImport("User32.dll", EntryPoint = "SendMessage", CharSet =
CharSet.Auto)]
private static extern int SendMessageRefRect(IntPtr hWnd, UInt32 Msg, int
wParam, ref RECT rect);

private const int EM_SETRECT = 0xB3;

public static void SetTextBoxFormatingRectangle(TextBoxBase textbox,
Rectangle rect)
{
RECT rc = new RECT(rect);
SendMessageRefRect(textbox.Handle, EM_SETRECT, 0, ref rc);
}

You could also use the EM_SETMARGINS message, but that doesn't give you
control over the top and bottom.

Tom Clement
Apptero, Inc.
"Patrick De Ridder" <00*@000.00> wrote in message
news:q1********************************@4ax.com...
Re displaying text in a multi-line text box:

Is it possible to have a margin on the left hand side, or on both
sides, so the text doesn't come right up to the border(s)?

Many thanks.
--
Regards,
Patrick.

Nov 15 '05 #2
"Tom Clement" <To***********@Apptero.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Yes it is. This should do it for you:

[DllImport("User32.dll", EntryPoint = "SendMessage", CharSet =
CharSet.Auto)]
private static extern int SendMessageRefRect(IntPtr hWnd, UInt32 Msg, int
wParam, ref RECT rect);

private const int EM_SETRECT = 0xB3;

public static void SetTextBoxFormatingRectangle(TextBoxBase textbox,
Rectangle rect)
{
RECT rc = new RECT(rect);
SendMessageRefRect(textbox.Handle, EM_SETRECT, 0, ref rc);
}

You could also use the EM_SETMARGINS message, but that doesn't give you
control over the top and bottom.

Tom Clement
Apptero, Inc.


Thanks a lot. I am impressed!

I have pasted in your code above #region Windows Form Designer generated
code
and I get this message upon compilation:
The type or namespace name 'RECT' could not be found (are you missing a
using directive or an assembly reference?)
--
Regards,
Patrick.

Nov 15 '05 #3
Darn it, I forgot to include that definition. Here is it...

public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;

public RECT(Rectangle rc) { Left = rc.Left; Top = rc.Top; Right =
rc.Right; Bottom = rc.Bottom; }
public RECT(int l, int t, int r, int b) { Left = l; Top = t; Right = r;
Bottom = b; }
public override string ToString() { return String.Format("RECT
({0},{1})-({2},{3})", Left, Top, Right, Bottom); }
}

Tom Clement
Apptero, Inc.

"Patrick De Ridder" <00*@000.00> wrote in message
news:10***************@evisp-news-01.ops.asmr-01.energis-idc.net...
"Tom Clement" <To***********@Apptero.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Yes it is. This should do it for you:

[DllImport("User32.dll", EntryPoint = "SendMessage", CharSet =
CharSet.Auto)]
private static extern int SendMessageRefRect(IntPtr hWnd, UInt32 Msg, int wParam, ref RECT rect);

private const int EM_SETRECT = 0xB3;

public static void SetTextBoxFormatingRectangle(TextBoxBase textbox,
Rectangle rect)
{
RECT rc = new RECT(rect);
SendMessageRefRect(textbox.Handle, EM_SETRECT, 0, ref rc);
}

You could also use the EM_SETMARGINS message, but that doesn't give you
control over the top and bottom.

Tom Clement
Apptero, Inc.


Thanks a lot. I am impressed!

I have pasted in your code above #region Windows Form Designer generated
code
and I get this message upon compilation:
The type or namespace name 'RECT' could not be found (are you missing a
using directive or an assembly reference?)
--
Regards,
Patrick.

Nov 15 '05 #4

"Tom Clement" <To***********@Apptero.com> wrote in message
news:uR**************@TK2MSFTNGP09.phx.gbl...
Darn it, I forgot to include that definition. Here is it...

public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;

public RECT(Rectangle rc) { Left = rc.Left; Top = rc.Top; Right =
rc.Right; Bottom = rc.Bottom; }
public RECT(int l, int t, int r, int b) { Left = l; Top = t; Right = r;
Bottom = b; }
public override string ToString() { return String.Format("RECT
({0},{1})-({2},{3})", Left, Top, Right, Bottom); }
}

Thanks you for the addition!
There seems to be one last hurdle
The type or namespace name 'DllImport' could not be found (are you missing a
using directive or an assembly reference?)
--
Regards
Patrick.

Nov 15 '05 #5
using System.Runtime.InteropServices;

Tom Clement
Apptero, Inc.

"Patrick De Ridder" <00*@000.00> wrote in message
news:10***************@evisp-news-01.ops.asmr-01.energis-idc.net...

"Tom Clement" <To***********@Apptero.com> wrote in message
news:uR**************@TK2MSFTNGP09.phx.gbl...
Darn it, I forgot to include that definition. Here is it...

public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;

public RECT(Rectangle rc) { Left = rc.Left; Top = rc.Top; Right =
rc.Right; Bottom = rc.Bottom; }
public RECT(int l, int t, int r, int b) { Left = l; Top = t; Right = r; Bottom = b; }
public override string ToString() { return String.Format("RECT
({0},{1})-({2},{3})", Left, Top, Right, Bottom); }
}
Thanks you for the addition!
There seems to be one last hurdle
The type or namespace name 'DllImport' could not be found (are you missing

a using directive or an assembly reference?)
--
Regards
Patrick.

Nov 15 '05 #6
> Thanks you for the addition!
There seems to be one last hurdle
The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?)
--
Regards
Patrick.


It would appear that this is the required reference
using System.Runtime.InteropServices;
I am left with the question how to apply it.
If anyone knows how, I would be very obliged with an example.
--
Regards
Patrick.
Nov 15 '05 #7

"Patrick De Ridder" <00*@000.00> wrote in message
news:10***************@evisp-news-01.ops.asmr-01.energis-idc.net...

It would appear that this is the required reference:

using System.Runtime.InteropServices;

**************

Presumably this should do the trick:
SetTextBoxFormatingRectangle(textBox1, 10)

It doesn't work.

The second parameter generates problems.

Any suggestions?

If this isn't the way to implement the code, what is the right way?

--
Patrick.

Nov 15 '05 #8
On Mon, 13 Oct 2003 12:05:41 -0700, "Tom Clement"
<To***********@Apptero.com> wrote:
Darn it, I forgot to include that definition. Here is it...

public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;

public RECT(Rectangle rc) { Left = rc.Left; Top = rc.Top; Right =
rc.Right; Bottom = rc.Bottom; }
public RECT(int l, int t, int r, int b) { Left = l; Top = t; Right = r;
Bottom = b; }
public override string ToString() { return String.Format("RECT
({0},{1})-({2},{3})", Left, Top, Right, Bottom); }
}

Tom Clement
Apptero, Inc.


(I have solved the reference problem.)

Presumably this is how your code should be invoked:
SetTextBoxFormatingRectangle(textBox1,10);

But it doesn't work. The second parameter gives problems.

--
Regards,
Patrick.
Nov 15 '05 #9
Hi Patrick,
In the code I provided, the second parameter is a Rectangle. That needs to
be the case, since the call provides for offsets on the Top, Right, Bottom
and Left. Here's how I call the method:

API.SetTextBoxFormatingRectangle(txtBody, new Rectangle(10,16,
txtBody.ClientSize.Width - 12, txtBody.ClientSize.Height - 20));

But to be honest with you, Patrick, this is the sort of thing you should be
able to figure out on your own. I'd recommend that you take a course at a
community college if something is available, or buy a good book on
programming. Once you get going, things turn out to be pretty
straightforward in C#, but it can be a bit of a hurdle initially.

Tom

"Patrick De Ridder" <00*@000.00> wrote in message
news:7o********************************@4ax.com...
On Mon, 13 Oct 2003 12:05:41 -0700, "Tom Clement"
<To***********@Apptero.com> wrote:
Darn it, I forgot to include that definition. Here is it...

public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;

public RECT(Rectangle rc) { Left = rc.Left; Top = rc.Top; Right =
rc.Right; Bottom = rc.Bottom; }
public RECT(int l, int t, int r, int b) { Left = l; Top = t; Right = r;Bottom = b; }
public override string ToString() { return String.Format("RECT
({0},{1})-({2},{3})", Left, Top, Right, Bottom); }
}

Tom Clement
Apptero, Inc.


(I have solved the reference problem.)

Presumably this is how your code should be invoked:
SetTextBoxFormatingRectangle(textBox1,10);

But it doesn't work. The second parameter gives problems.

--
Regards,
Patrick.

Nov 15 '05 #10
On Wed, 15 Oct 2003 10:29:51 -0700, "Tom Clement"
<To***********@Apptero.com> wrote:
But to be honest with you, Patrick, this is the sort of thing you should be
able to figure out on your own. I'd recommend that you take a course at a
community college if something is available, or buy a good book on
programming. Once you get going, things turn out to be pretty
straightforward in C#, but it can be a bit of a hurdle initially.


First of all thank you. Secondly, sure I still have a hell of a lot to
learn. However, I have been reading and will go on doing so.
--
Regards,
Patrick.
Nov 15 '05 #11

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

Similar topics

1
by: Gary Richardson | last post by:
I've been working on a Python version of Andreas Weber's ASCII schematic drawing program ( http://www.tech-chat.de) ; not that I thought I could do it better but just as a programming exercise....
0
by: Randell D. | last post by:
Folks, I need to store what amounts to a story, or article text in to a table - Its likely that most articles will not exceed 2000 characters however I came up with the idea of having three tables...
0
by: Paul Bramscher | last post by:
I'm working on application which stores web page content. Generally I'm turning the whole page into base64 for ease of storage (into a TEXT field). But I have another field which opens a socket...
1
by: Patrick De Ridder | last post by:
When I code Double.Parse(textBox1.Text) I get an error How can I convert a text box entry to a numeric? Please give a code example, if you know the answer.
1
by: Du | last post by:
When I copy a paragraph from IE and paste it to a richtextbox, I get the the text and the underlying format How do I get the just the text without the html code ? thanks
6
by: MPR | last post by:
Hi guys; I got HTML code assigned to a variable. Actually what I got into the variable is the whole HTML code for a web page. I want to save that HTML code to disk, but not as HTML, I wan to...
12
by: Boris Borcic | last post by:
Hello, I am trying to use UI Automation to drive an MS Windows app (with pywinauto). I need to scrape the app's window contents and use some form of OCR to get at the texts (pywinauto can't...
2
by: =?Utf-8?B?Q2h1Y2sgUA==?= | last post by:
I am trying to retrieve the @AnswerCount Attribute for the @QuestionID=1 AND the Answer element text =3 I successfully can pass the variables QuestionID and Answer but can't pull out the...
2
by: bobdydd | last post by:
Hi All In the plan text version of a Memo field you can easily add a date by pressing Ctrl+Colon which makes life easy for the end user. However, if the Memo field is set to the Rich Text...
1
by: =?Utf-8?B?c2luZ211c2lrMDQ=?= | last post by:
Anyone know how to create a text whereas its just normal text, however you can bend it in a semi circle....In other words, I DO NOT want to use word art, but I do want to bend normal fonts in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...
0
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,...
0
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...
0
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...

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.