|
fredsparkle wrote: Does anyone have a better solution?
Well I was going to suggest something until I saw you voted down my post.
led mike
|
|
|
|
|
Yep, you are not the first victim of the modern voting system.
Best way to avoid this (or reduce its probability) is to modify
the message type away from "answer" when the only thing you (rightfully) do
is ask some questions, since those questions are strictly not an "helpful answer"
to the OP.
|
|
|
|
|
Luc Pattyn wrote: Best way to avoid this (or reduce its probability) is to modify
the message type away from "answer" when the only thing you (rightfully) do
is ask some questions
Perhaps, but that doesn't stop the 'Bad Question' voting mechanism which just equates to a '1' correct?
Also, the default message type isn't "Answer" anyway, it's "General Comment".
led mike
|
|
|
|
|
Hi led mike
The question was did your solve my problem and sorry the answer to was no, it only gave me two choices; so thats what I clicked.
|
|
|
|
|
fredsparkle wrote: The question was did your solve my problem and sorry the answer to was no, it only gave me two choices; so thats what I clicked.
proving my point exactly.
|
|
|
|
|
Thanks fred. May I suggest that until everyone gets the hang of this new voting mechanism you only vote Yes otherwise don't vote at all.
led mike
|
|
|
|
|
led mike wrote: that doesn't stop the 'Bad Question' voting mechanism
Well, if you ask bad questions (whatever that is), then 1 is what you deserve.
led mike wrote: the default message type isn't "Answer" anyway, it's "General Comment".
I don't think so. The first-level reply to a question is an answer by default (like this one).
|
|
|
|
|
Ok got rid of the annoying flash. The problem with the timer approach is that its minimum granularity is 1/10 of a second.
The final solution is to define a delegate which under the covers (way deep) does a Post Message, so the refresh operation happens after it hides everything when the ballon tip goes away.
In the main custom control:
public delegate void InvokeDelegate();
tb_password.Tag = (object)new InvokeDelegate(Refresh);
Our extended textbox:
public class PasswordControl : TextBox<br />
{<br />
private const int EM_HIDEBALLOONTIP = 0x1504;<br />
protected override void WndProc(ref Message m)<br />
{<br />
if (m.Msg == EM_HIDEBALLOONTIP)<br />
{<br />
Delegate del = (Delegate)this.Tag;<br />
this.BeginInvoke(del);<br />
}<br />
base.WndProc(ref m);<br />
}<br />
}<br />
Theory of operation:
1. Create a delegate for the refresh operation for the master custom control container.
2. Assign it as a tag to the textbox that is used as a password field.
3. Extend the textbox class to monitor for the hide ballon tip messages.
4. When the extended textbox class sees that there is a closing ballon tip it instructs the master control to refresh it self via the previously created delegate.
|
|
|
|
|
Luc Pattyn wrote: I don't think so. The first-level reply to a question is an answer by default (like this one).
I see you are correct. Although at times the "General Comment" is the default like in this current reply. Ok I guess the default changes based on the type of the post you are replying to, I never knew that. Thanks for pointing all this out to me, although I imagine it will take me some time to start remembering to select a type, I never used to worry about it aside from occasional use of the joke type.
led mike
|
|
|
|
|
Hi guys,
I have a problem with event on key press enter.
I have a TextBox1, then I am a typing to him and I need to if KeyPress was ENTER call my function Result().
I think I can not do something function like that:
<br />
void textBox1_KeyPress( Object^ , System::Windows::Forms::KeyPressEventArgs^ e )<br />
{<br />
if(e->KeyCode == Key::Enter)
Result();
}<br />
I am looking for some pieces of code in msdn, but I still have a problem somewhere.
KeyPreview in Properties Form1 is true.
I am so sorry for this stupid question
|
|
|
|
|
From the docs:
"The KeyPress event is not raised by noncharacter keys;
however, the noncharacter keys do raise the KeyDown and
KeyUp events."
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks, but I still not work. I have this:
void textBox1_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
{
if ( e->KeyCode == Keys::Enter)
textBox2->Text = "Enter was pressed";
}
|
|
|
|
|
Polar_Sheep wrote: I still not work
Maybe try setting the TextBox's AcceptsReturn property to true.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
AcceptsReturn True... Still is not work. Shall I have some code in Initialize component?
I mean something like this:
this->textBox1->KeyDown = gcnew... something?
|
|
|
|
|
Yes you need to create the delegate and add it to the event.
Can you show that code?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
#pragma once
namespace PoHavarii {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1;
protected:
private: System::Windows::Forms::TextBox^ textBox2;
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// textBox1
//
this->textBox1->AcceptsReturn = true;
this->textBox1->Location = System::Drawing::Point(108, 55);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(181, 20);
this->textBox1->TabIndex = 0;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(108, 94);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(181, 20);
this->textBox2->TabIndex = 1;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(391, 264);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->textBox1);
this->KeyPreview = true;
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
void textBox1_KeyDown( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
{
if ( e->KeyCode == Keys::Enter)
textBox2->Text = L"Enter was pressed";
}
};
}
|
|
|
|
|
In initializeComponent(), create a delegate and add it to textBox1's KeyDown event:
this->textBox1->KeyDown += gcnew System::KeyEventHandler(this, &Form1::textBox1_KeyDown);
Mark
*edit* Fixed code in bold
Mark Salsbery
Microsoft MVP - Visual C++
modified on Saturday, July 26, 2008 4:35 PM
|
|
|
|
|
'void PoHavarii::Form1::textBox1_KeyDown(System::Object ^,System::Windows::Forms::KeyEventArgs ^)' : the specified function does not match the delegate type 'void (System::Object ^,System::EventArgs ^)'
It needs other function, but we are on the right way Many thanks
|
|
|
|
|
this->textBox1->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::textBox1_KeyDown); Thank you very much and sorry for your time
|
|
|
|
|
Oops! You got it
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I assume you added the TextBox to your form using the designer. An easy way to add events to a control is to view the Properties window for the control (just right-click on the TextBox and select Properties if it's not already showing). The default view shows most of the public properties you can access for that control (things like Text, Enabled, Visible, Height, etc.). There's a button with a lightning bolt at the top of this window. Clicking this button will show all the events this control has. Double-clicking on an event will automatically insert the function and link it to your control in InitializeComponent().
Slightly longer explanation than I wanted, but once you walk through it, it's really easy. I just with it would place the function definitions in Form1.cpp instead of Form1.h
- dybs
|
|
|
|
|
This is a problem I've had since I started using C++/CLI
take for example this simple ref class
ref class CFoo
{
public:
String^ text;
CFoo(void)
{
this->text = "";
}
CFoo(const CFoo^ _cpy)
{
this->text = _cpy->text;
}
void operator=(const CFoo^ _rhs)
{
this->text = _rhs->text;
}
};
And now a main that has a couple CFoo variables
int main(void)
{
CFoo^ foo1 = gcnew CFoo();
CFoo^ foo2 = gcnew CFoo();
foo1->text = "Bill";
foo2 = foo1;
foo1->text = "Bob";
return 0;
}
When I run this when I run foo2 = foo1; " my assignment operator is never called and all that happens is the handle from foo1 is given to foo2. Then when I change the text of foo1 it "changes" foo2 which is just at this point a reference to foo1;
Now if I swap out
foo2 = foo1;
with
foo2->operator =(foo1);
then everything works as I expect it.
The way I have always gotten around this was to call the copy constructor like so
foo2 = gcnew CFoo(foo1);
Although this works in my opinion it doesn't look as nice as a simple = operator.
So what I'm looking for is to get foo1 = foo2; to call my assignment operator or is it just not possible? I've googled it to death and although its not stopping my program from working it's been something thats been bugging me to death.
modified on Thursday, July 24, 2008 12:05 AM
|
|
|
|
|
If you assign a handle to a managed object to another
handle to a managed object of the same type, only the
handle is copied.
To get a distinct new copy you can do one of the following:
1) Call your assignment operator explicitly (wasteful - why do a construct then an assignment?)
2) Use a copy constructor
3) Implement ICloneable in your class and use its Clone() method
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
What mark said. If you want to read more about why this is the case you might read some of Lippmans comments on C++/CLI like this article[^]
led mike
|
|
|
|
|