Click here to Skip to main content
15,921,113 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionBYTE to unsigned char Pin
samkook27-Oct-06 12:54
samkook27-Oct-06 12:54 
AnswerRe: BYTE to unsigned char Pin
Christian Graus27-Oct-06 15:54
protectorChristian Graus27-Oct-06 15:54 
GeneralRe: BYTE to unsigned char Pin
samkook27-Oct-06 19:12
samkook27-Oct-06 19:12 
GeneralRe: BYTE to unsigned char Pin
Christian Graus28-Oct-06 2:19
protectorChristian Graus28-Oct-06 2:19 
GeneralRe: BYTE to unsigned char Pin
samkook28-Oct-06 9:08
samkook28-Oct-06 9:08 
GeneralRe: BYTE to unsigned char Pin
Christian Graus28-Oct-06 11:26
protectorChristian Graus28-Oct-06 11:26 
GeneralRe: BYTE to unsigned char Pin
Mark Salsbery29-Oct-06 17:23
Mark Salsbery29-Oct-06 17:23 
QuestionUser Painted TextBox Pin
Tojiro26-Oct-06 8:39
Tojiro26-Oct-06 8:39 
A few questions from a long time programmer but .NET newbie:
I seem to be having an awful lot of trouble getting a textbox set up that will properly use the userpaint flag. Whenever I set it, I can then override the onPaint and onBackgroundPaint functions and have them do their own thing (such as filling the background with a gradient, which is my immediate goal) but it seems that there is still a lot of things that the textbox control simply draws on it's own without any input from me: Cursors, borders, selected text, etc.
Is there anything further I need to override in order to completely control the control painting, or is this simply one of those things that are *shudder* hardcoded into the system?

Some sample code, for kicks:
<br />
public ref class MyTextBox : public System::Windows::Forms::TextBox<br />
	{<br />
	public:<br />
		MyTextBox (void)<br />
		{<br />
			this->SetStyle(ControlStyles::UserPaint | ControlStyles::AllPaintingInWmPaint, true);<br />
			this->SetStyle(ControlStyles::SupportsTransparentBackColor, true);<br />
			this->SetStyle(ControlStyles::OptimizedDoubleBuffer, true);<br />
		}<br />
<br />
	protected:<br />
		~MyTextBox ()<br />
		{<br />
			if (components)	{ delete components; }<br />
		}<br />
<br />
	private:<br />
		System::ComponentModel::Container ^components;<br />
<br />
	protected:<br />
		virtual void OnPaintBackground(PaintEventArgs^ e) override {<br />
			Drawing::Brush^ backBrush = gcnew Drawing2D::LinearGradientBrush(<br />
				this->ClientRectangle,<br />
				Color::AliceBlue, <br />
				Color::LightBlue,<br />
				Drawing2D::LinearGradientMode::Vertical);<br />
<br />
			e->Graphics->FillRectangle(backBrush, this->ClientRectangle);<br />
<br />
			delete backBrush;<br />
		}<br />
<br />
		virtual void OnPaint(PaintEventArgs^ e) override {<br />
			System::Drawing::Brush^ tBrush = SystemBrushes::ControlText;<br />
<br />
			StringFormat^ tFormat = gcnew StringFormat();<br />
			tFormat->Alignment = StringAlignment::Near;<br />
			tFormat->LineAlignment = StringAlignment::Near;<br />
			tFormat->Trimming = StringTrimming::None;<br />
<br />
			e->Graphics->DrawString(this->Text, this->Font, tBrush, this->ClientRectangle, tFormat);<br />
		}<br />


A few other questions, if anyone cares to answer:
-Is there a CLI equivalent to the C# "base" keyword? I have plenty of times that I'd like to call something like base.OnPaint(), but there doesn't seem to be a resonable way of doing that in C++/CLI. (For example, in my code above TextBox::OnPaint(e) would NOT work, it would simply call my overridden version.)
-If I declare a virtual function as "new" (as opposed to override), how in the world to I call it? It always seems to default to the function for the class I inherited it from.
-Is there a way that you can just override OnPaintBackground without overriding OnPaint? I thought you could just leave out your own OnPaint definition, but this doesn't appear to work so well in practice (for instance: all my fonts become an ugly bold "system" font)

Thanks in advance for all your help!
Questionwriting test results in XML file using CPPUnit Pin
jayart26-Oct-06 5:21
jayart26-Oct-06 5:21 
QuestionUnmanaged pointer in managed collection Pin
Jose M Castellanos26-Oct-06 1:15
Jose M Castellanos26-Oct-06 1:15 
AnswerRe: Unmanaged pointer in managed collection Pin
User 58385226-Oct-06 13:41
User 58385226-Oct-06 13:41 
AnswerRe: Unmanaged pointer in managed collection Pin
George L. Jackson28-Oct-06 6:45
George L. Jackson28-Oct-06 6:45 
Questionread all files form a CD Pin
Iv0125-Oct-06 14:01
Iv0125-Oct-06 14:01 
AnswerRe: read all files form a CD Pin
Jonathan [Darka]25-Oct-06 21:14
professionalJonathan [Darka]25-Oct-06 21:14 
QuestionTemplate question Pin
User 58385224-Oct-06 15:16
User 58385224-Oct-06 15:16 
AnswerRe: Template question Pin
Rob Graham24-Oct-06 17:07
Rob Graham24-Oct-06 17:07 
GeneralRe: Template question Pin
User 58385224-Oct-06 18:48
User 58385224-Oct-06 18:48 
QuestionUnderstanding Templates Pin
Nathan Farrar23-Oct-06 4:51
Nathan Farrar23-Oct-06 4:51 
AnswerRe: Understanding Templates Pin
led mike23-Oct-06 7:56
led mike23-Oct-06 7:56 
AnswerRe: Understanding Templates Pin
Michael Dunn23-Oct-06 13:28
sitebuilderMichael Dunn23-Oct-06 13:28 
AnswerRe: Understanding Templates Pin
George L. Jackson23-Oct-06 13:31
George L. Jackson23-Oct-06 13:31 
GeneralRe: Understanding Templates Pin
Nathan Farrar24-Oct-06 1:54
Nathan Farrar24-Oct-06 1:54 
QuestionC++/CLI std::wstring behaving VERY strangely with /MD Pin
Raeldor_22-Oct-06 21:36
Raeldor_22-Oct-06 21:36 
AnswerRe: C++/CLI std::wstring behaving VERY strangely with /MD Pin
led mike23-Oct-06 5:02
led mike23-Oct-06 5:02 
GeneralRe: C++/CLI std::wstring behaving VERY strangely with /MD [modified] Pin
Raeldor_23-Oct-06 5:47
Raeldor_23-Oct-06 5:47 

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.