why it's paint not work? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
wunekky
In need of some credit
In need of some credit
Posts: 8
Joined: Wed May 13, 2009 12:30 am

why it's paint not work?

Post by wunekky »

MouseEvent:

Code: Select all

void CalculateDlg::OnMouse(wxMouseEvent &event)
{
	wxPoint pt(event.GetPosition());
	if((pt.x>0)&&(pt.x<68)&&(pt.y>165)&&(pt.y<165+60)&&(event.LeftDown()))
	{
		ButtonSel = num1;

	}
	if(event.LeftDown())
		ButtonSel = num1;

}
paint:

Code: Select all

    if(ButtonSel==num1)
	{
		wxBufferedPaintDC mydc(this);
		mydc.SetPen(*wxBLACK_PEN);
		mydc.SetBrush(wxColour(255,155,0)/**wxRED_BRUSH*/);
		DrawTextString(mydc,wxT("test"),wxPoint(50,50) );
	}
why "test" cann't paint in dialog?
come form china;
van_user
Experienced Solver
Experienced Solver
Posts: 55
Joined: Wed Jun 11, 2008 9:28 pm
Location: UA

Post by van_user »

Try to call "Invalidate" or "Refresh" methods. Also for test set if statement to "true".
wunekky
In need of some credit
In need of some credit
Posts: 8
Joined: Wed May 13, 2009 12:30 am

Post by wunekky »

thinks,then like this:
MouseEvent:

Code: Select all

void CalculateDlg::OnMouse(wxMouseEvent &event)
{
	wxPoint pt(event.GetPosition());
	if(event.LeftDown())
		ButtonSel = 1;

}
Paint:

Code: Select all

    if(ButtonSel==1)
	{
		wxBufferedPaintDC mydc(this);
		wxFont font(30,wxFONTFAMILY_SCRIPT  ,wxNORMAL,wxBOLD);
		mydc.SetFont(font);
		mydc.SetTextForeground(*wxRED);
		mydc.DrawText(wxT("test"),wxPoint(50,50));
	}
if the segment set 1,it can paint,so why the segment not equ 1?
come form china;
van_user
Experienced Solver
Experienced Solver
Posts: 55
Joined: Wed Jun 11, 2008 9:28 pm
Location: UA

Post by van_user »

:) Do you hit left button on the mouse?
Do you clear "ButtonSel" when not event.LeftDown()?
"LeftDown - Returns true if the left mouse button changed to down." Maybe if button state is already down then method return false?
wunekky
In need of some credit
In need of some credit
Posts: 8
Joined: Wed May 13, 2009 12:30 am

Post by wunekky »

Do you hit left button on the mouse?
of course.

Do you clear "ButtonSel" when not event.LeftDown()?
the ButtonSel is a global variable ,just used in this place.

"LeftDown - Returns true if the left mouse button changed to down." Maybe if button state is already down then method return false?
if button state is already down,the ButtonSel will be set to 1,then it will keep 1.
Mouse up,the if segment will be false ,but the ButtonSel's value still is 1.why it cann't paint?
come form china;
van_user
Experienced Solver
Experienced Solver
Posts: 55
Joined: Wed Jun 11, 2008 9:28 pm
Location: UA

Post by van_user »

wunekky wrote: if button state is already down,the ButtonSel will be set to 1,then it will keep 1.
Mouse up,the if segment will be false ,but the ButtonSel's value still is 1.why it cann't paint?
I have only 2 versions:
1 - ButtonSel never set to 1
2 - ButtonSel somewhere set to not 1.
Without code I can`t say more.
Try debugger - stop on

Code: Select all

if(event.LeftDown())
and inspect value of ButtonSel or output message with its value using cout/printf or MessageBox.
wunekky
In need of some credit
In need of some credit
Posts: 8
Joined: Wed May 13, 2009 12:30 am

Post by wunekky »

debugger:the value if ButtonSel set to 1.
just like the string will be paint,but then it will be cover with something.
come form china;
van_user
Experienced Solver
Experienced Solver
Posts: 55
Joined: Wed Jun 11, 2008 9:28 pm
Location: UA

Post by van_user »

wunekky wrote:just like the string will be paint,but then it will be cover with something.
I don`t think so: you said that if statement of

Code: Select all

if(ButtonSel==1)
        { wxBufferedPaintDC mydc(this);
               ...
          mydc.DrawText(wxT("test"),wxPoint(50,50));}
set to true programme work well - why something don`t cover your text in that case? But maybe I am wrong. Need code to test.
wunekky
In need of some credit
In need of some credit
Posts: 8
Joined: Wed May 13, 2009 12:30 am

Post by wunekky »

:o add Refresh,it work on.

Code: Select all

void CalculateDlg::OnMouse(wxMouseEvent &event) 
{ 
        wxPoint pt(event.GetPosition()); 
        if(event.LeftDown()) 
        {
                ButtonSel = 1; 
                Refresh();
        }

}
but when the mouse down,i have a flicker.
come form china;
van_user
Experienced Solver
Experienced Solver
Posts: 55
Joined: Wed Jun 11, 2008 9:28 pm
Location: UA

Post by van_user »

wunekky wrote::o
but when the mouse down,i have a flicker.
:) Try this:

Code: Select all

void CalculateDlg::OnMouse(wxMouseEvent &event) 
{ 
        wxPoint pt(event.GetPosition()); 
        if( ButtonSel != 1 && event.LeftDown()) 
        {
                ButtonSel = 1; 
                Refresh();
        }

}
wunekky
In need of some credit
In need of some credit
Posts: 8
Joined: Wed May 13, 2009 12:30 am

Post by wunekky »

:? maybe casuse of PNG image...
come form china;
Post Reply