Click here to Skip to main content
15,886,724 members
Home / Discussions / C#
   

C#

 
GeneralRe: Using IActiveDesktop in C# Pin
Heath Stewart29-Dec-03 5:51
protectorHeath Stewart29-Dec-03 5:51 
GeneralRe: Using IActiveDesktop in C# Pin
Okeno Palmer29-Dec-03 11:12
Okeno Palmer29-Dec-03 11:12 
GeneralBuilding Office add-ins in C# Pin
Member 78647328-Dec-03 10:36
Member 78647328-Dec-03 10:36 
GeneralRe: Building Office add-ins in C# Pin
Michael P Butler28-Dec-03 11:36
Michael P Butler28-Dec-03 11:36 
GeneralRe: Building Office add-ins in C# Pin
Member 78647328-Dec-03 11:50
Member 78647328-Dec-03 11:50 
QuestionHow to kill Excel process properly? Pin
teagermylk28-Dec-03 10:31
teagermylk28-Dec-03 10:31 
QuestionWIN32 DrawText() .NET equivalent?? Pin
ShaneStump28-Dec-03 8:11
ShaneStump28-Dec-03 8:11 
AnswerRe: WIN32 DrawText() .NET equivalent?? Pin
Heath Stewart28-Dec-03 9:11
protectorHeath Stewart28-Dec-03 9:11 
See the StringFormat class (the defaults should do, but you can create your own) and the Graphics.DrawString method, which you can use in the OnPaint method override (always override methods instead of handling events in derived classes, but make sure to call the base class's method in most cases):
protected override void OnPaint(PaintEventArgs e)
{
  RectangleF rectF = GetRectFBoundsForControl(); // Made-up method to
    // get the bounds in which text can be drawn.
  e.Graphics.DrawString("Some multi-line text",
    this.Font,
    new SolidBrush(SystemColors.ControlText),
    rectF,
    StringFormat.GenericDefault); // Or create your own
}
Otherwise, you can always just P/Invoke DrawText, define the DT_CALCRECT and DT_WORDBREAK constants (or enum values) based on the preproc def values, and call the method using the control's HDC, which you can get during the Paint event (override OnPaint when deriving from Control instead):
protected override void OnPaint(PaintEventArgs e)
{
  base.OnPaint(e);
  IntPtr hdc = e.Graphics.GetHdc();
  DrawText(hdc, "Some Text", ...);
  e.Graphics.ReleaseHdc(hdc);
}
You'll also need to define the RECT structure to use in managed code. See the StructLayoutAttribute for details.

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralRe: WIN32 DrawText() .NET equivalent?? Pin
ShaneStump28-Dec-03 10:48
ShaneStump28-Dec-03 10:48 
GeneralRe: WIN32 DrawText() .NET equivalent?? Pin
Nick Parker28-Dec-03 11:02
protectorNick Parker28-Dec-03 11:02 
GeneralRe: WIN32 DrawText() .NET equivalent?? Pin
ShaneStump28-Dec-03 11:11
ShaneStump28-Dec-03 11:11 
GeneralRe: WIN32 DrawText() .NET equivalent?? Pin
Nick Parker28-Dec-03 11:34
protectorNick Parker28-Dec-03 11:34 
GeneralRe: WIN32 DrawText() .NET equivalent?? Pin
ShaneStump28-Dec-03 11:46
ShaneStump28-Dec-03 11:46 
GeneralTreeView Pin
Luther Baker28-Dec-03 7:48
Luther Baker28-Dec-03 7:48 
GeneralRe: TreeView Pin
Tristan Rhodes28-Dec-03 8:37
Tristan Rhodes28-Dec-03 8:37 
GeneralRe: TreeView Pin
Heath Stewart28-Dec-03 8:58
protectorHeath Stewart28-Dec-03 8:58 
GeneralYe - That one Pin
Tristan Rhodes28-Dec-03 14:22
Tristan Rhodes28-Dec-03 14:22 
GeneralThanks Pin
Luther Baker30-Dec-03 5:09
Luther Baker30-Dec-03 5:09 
GeneralRe: TreeView Pin
Luther Baker30-Dec-03 9:51
Luther Baker30-Dec-03 9:51 
GeneralRe: TreeView Pin
Heath Stewart30-Dec-03 10:59
protectorHeath Stewart30-Dec-03 10:59 
GeneralRe: TreeView Pin
Luther Baker31-Dec-03 4:47
Luther Baker31-Dec-03 4:47 
GeneralRe: TreeView Pin
Luther Baker31-Dec-03 4:56
Luther Baker31-Dec-03 4:56 
GeneralC Pre Processor executable Pin
Tristan Rhodes28-Dec-03 5:38
Tristan Rhodes28-Dec-03 5:38 
GeneralRe: C Pre Processor executable Pin
Tristan Rhodes28-Dec-03 5:44
Tristan Rhodes28-Dec-03 5:44 
GeneralRe: C Pre Processor executable Pin
Nick Parker28-Dec-03 5:56
protectorNick Parker28-Dec-03 5:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.