Windows Develop Bookmark and Share   
 index > Windows Forms Designer > The VisibleClipBounds is not modified by SetClip function
 

The VisibleClipBounds is not modified by SetClip function

Hi everyone!
In order to draw I firstcreate a Graphicsobject into the FormLoad... (I don't want to use the Graphics object of the Paint Event)
When resizing the form, I see that the VisibleClipBounds is not modified.
I tried to use the Function SetClip which modifies the ClipBounds only, but it does not modify the VisibleClipBounds!

This is thecode (Visual C++ 2008 SP1):

Graphics ^g;
//FormLoad
g = this->CreateGraphics();
g->PageUnit=GraphicsUnit::Pixel;

//FormPaint
g->ResetClip();
g->SetClip(RectangleF(0.0f, 0.0f, 500.0f, 400.0f));
g->Clear(Color::LightBlue);

Thank you for your help!

obiwan74ita  Wednesday, July 08, 2009 4:57 PM
Someone knows how to help me?
thanks.
obiwan74ita  Thursday, July 09, 2009 3:12 PM
When resizing the form, I see that the VisibleClipBounds is not modified.
I tried to use the Function SetClip which modifies the ClipBounds only, but it does not modify the VisibleClipBounds!
Hi obiwan74ita,

To draw something onto the form, you need to handle Paint event of the form instead of Load event. In this case, I have handled the Paint event and copied your code. I don't see the problem. But I still don't know the meaning of your post. Could you please explain it clearly?

Sincerely,
Kira Qian

Please mark the replies as answers if they help and unmark if they don't.
Kira Qian  Friday, July 10, 2009 3:41 AM
Hello Kira Qian,
thank you for your reply.

I need to create the Graphics object externally of the Paint event (into the FormLoad) because I have to access it into other routines (MouseMove for example...)
When resizing the form, I see that the VisibleClipBounds is not modified.

Here you can find the code

//MyForm.h

#pragma once

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

namespace MyProject {

    public ref class MyForm : public System::Windows::Forms::Form
    {
      public:
        MyForm(void)
        { 
          InitializeComponent();
          this->DoubleBuffered=true; 
          pMouse = gcnew array<PointF>(1);  
          mat=gcnew Matrix();
        }

      protected:

        ~MyForm()
        { 
          if(components) delete components;
          delete g;
        }

      private:

        System::ComponentModel::Container ^components;
      private: System::Windows::Forms::Label^  label1;

        Graphics ^g;
        System::Drawing::Drawing2D::Matrix ^mat;
        array<PointF> ^pMouse;

#pragma region Windows Form Designer generated code

        void InitializeComponent(void)
        {
          this->label1 = (gcnew System::Windows::Forms::Label());
          this->SuspendLayout();
          // 
          // label1
          // 
          this->label1->AutoSize = true;
          this->label1->Location = System::Drawing::Point(15, 10);
          this->label1->Name = L"label1";
          this->label1->Size = System::Drawing::Size(35, 13);
          this->label1->TabIndex = 0;
          this->label1->Text = L"label1";
          // 
          // MyForm
          // 
          this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
          this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
          this->ClientSize = System::Drawing::Size(200, 200);
          this->Controls->Add(this->label1);
          this->Name = L"MyForm";
          this->Text = L"MyForm";
          this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
          this->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &MyForm::MyForm_Paint);
          this->Resize += gcnew System::EventHandler(this, &MyForm::MyForm_Resize);
          this->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &MyForm::MyForm_MouseMove);
          this->ResumeLayout(false);
          this->PerformLayout();
        }
#pragma endregion

      private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e)
      {  
        mat->Scale(0.5f, -0.5f);
        mat->Translate(10.0f, -100.0f);
        g = this->CreateGraphics();
        g->PageUnit=GraphicsUnit::Pixel;		
        g->Transform=mat;
      }
      private: System::Void MyForm_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e)
      {         
        g->Clear(Color::LightBlue);
        // Draw ...
      }
      private: System::Void MyForm_Resize(System::Object^ sender, System::EventArgs^ e)
      { 
        g->ResetClip();
        g->SetClip(this->ClientRectangle);     
      }
      private: System::Void MyForm_MouseMove(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e)
      {
        pMouse[0].X=(float)e->X;
        pMouse[0].Y=(float)e->Y;
        g->TransformPoints(CoordinateSpace::World, CoordinateSpace::Device, pMouse);
        label1->Text="X, Y = "+pMouse[0].X.ToString("0.00")+", "+pMouse[0].Y.ToString("0.00"); //show world coordinate
      }
    };
}




thanks.
obiwan74ita  Friday, July 10, 2009 8:10 AM
Hi everyone!
Can you suggest me something more, please?
Is there anybody who can help me??
I hope you'll write me soon...

Thanks!
obiwan74ita  Monday, July 27, 2009 7:58 AM

You can use google to search for other answers

Custom Search

More Threads

• There is already a command handler for the menu command '5efc7975-14bc-11cf-9b2b-00aa00573819 : 17'
• MessageBox language
• AcceptButton and CancelButton keep being cleared :(
• How to capture and save resources generated by CodeDomDesignerLoader in Custom Designer
• PropertyGrid Reflection
• Derived tree control and the designer
• Getting 'MissingManifestResourceException' on derived control
• Silly question - but where are my VS 2008 (3.5) controls?
• Aligning List View Item
• datagridview design