CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2024
    Posts
    2

    C++ Error cannot convert parameter 1 from 'System::Drawing::Pen' to 'System::Drawing:

    Hi all,

    I am new to this group so I need your help. I'm working on my application to make the border for the panel.

    When I try this:

    Code:
        int thickness = 3;
        Pen pen(Color::DarkGray, thickness);
        Rectangle r = Rectangle(0, 0, panel2->ClientRectangle.Width, panel2->ClientRectangle.Height);
        e->Graphics->DrawRectangle(pen, r);

    I'm getting the error:

    Code:
        'void System::Drawing::Graphics::DrawRectangle(System::Drawing::Pen ^,System::Drawing::Rectangle)' : cannot convert parameter 1 from 'System::Drawing::Pen' to 'System::Drawing::Pen ^'


    The error are jumping on this line:

    Code:
        e->Graphics->DrawRectangle(pen, r);


    Here is the full code:

    Code:
       private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    	    panel2->BorderStyle = BorderStyle::None;
        }
    
        private: System::Void panel2_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
    	    int thickness = 3;
    			 
    
    		Pen pen(Color::DarkGray, thickness);
    		Rectangle r = Rectangle(0, 0, panel2->ClientRectangle.Width, panel2->ClientRectangle.Height);
    		e->Graphics->DrawRectangle(pen, r);
    
    	}

    I dont really understand why i am getting an error when I am trying to set the blue line border with a pen.

    Can you please show me an example what is the correct way to display the blue border for the panel??

    Thanks,
    Mark

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,401

    Re: C++ Error cannot convert parameter 1 from 'System::Drawing::Pen' to 'System::Draw

    See example in https://learn.microsoft.com/en-us/do...t-plat-ext-8.0

    PS: I had to move your OP to the appropriate forum
    Last edited by VictorN; February 25th, 2024 at 11:49 AM. Reason: The OP was osted to the wrong forum
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured