Form1->Size... => Error C2143



  • Hallo,

    Vorweg, ich programmiere normalerweise nichts mit c++ !

    Ich muss jetzt aber ein kleines Projekt machen und will darin die Größe meines Windows-Forms ändern wenn ich zwischen den Tabs in meinem TabControl hin und her wechsle:

    private: System::Void tabControl1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e)
    		 {
    			 if (tabControl1->SelectedTab->Name == "xxx")
    			 {
    				 Form1->Size = Size(Point(365, 397));
    			 }	 
    		 }
    

    Nun bekomm ich (2x) den Error C2143 angezeigt:

    error C2143: syntax error : missing ';' before '->'

    Hab keine Ahnung an was es liegt 😞

    Grüße



  • Hi,

    probier mal

    Form1->Size::set(System::Drawing::Size::Size(365, 397));
    

    bei mir klappts so

    Viele Grüße
    Cain



  • Jo erstmal danke für die schnelle Antwort, leider ist das Ergebnis mit deinem Code genau das selbe...



  • Form1 scheint mir der Klassenname zu sein und nicht der Name der Instanz, deren Größe du setzen willst.
    Irgendwo wirst du so was haben wie:

    Form1 ^ form = gcnew Form1();
    

    Das bedeutet, du kannst es dann so ansprechen:

    form->Size = //...
    


  • Hmm hab nichts derartiges gefunden...

    Mir ist aufgefallen, dass ich das Form im Designer gar nicht umbenennen kann!?

    Naja ich hab jetzt mal ein neues Projekt aufgemacht, in dem nur ein TabControl (mit 2 TabPages) ist.

    -->Selber Fehler

    Form1.h:

    #pragma once
    
    namespace CpLuSpLuS {
    
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    
    	/// <summary>
    	/// Summary for Form1
    	///
    	/// WARNING: If you change the name of this class, you will need to change the
    	///          'Resource File Name' property for the managed resource compiler tool
    	///          associated with all .resx files this class depends on.  Otherwise,
    	///          the designers will not be able to interact properly with localized
    	///          resources associated with this form.
    	/// </summary>
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    		}
    
    	protected:
    		/// <summary>
    		/// Clean up any resources being used.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::TabControl^  tabControl1;
    	protected: 
    	private: System::Windows::Forms::TabPage^  tabPage1;
    	private: System::Windows::Forms::TabPage^  tabPage2;
    
    	private:
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		System::ComponentModel::Container ^components;
    
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the code editor.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
    			this->tabPage1 = (gcnew System::Windows::Forms::TabPage());
    			this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
    			this->tabControl1->SuspendLayout();
    			this->SuspendLayout();
    			// 
    			// tabControl1
    			// 
    			this->tabControl1->Controls->Add(this->tabPage1);
    			this->tabControl1->Controls->Add(this->tabPage2);
    			this->tabControl1->Dock = System::Windows::Forms::DockStyle::Fill;
    			this->tabControl1->Location = System::Drawing::Point(0, 0);
    			this->tabControl1->Name = L"tabControl1";
    			this->tabControl1->SelectedIndex = 0;
    			this->tabControl1->Size = System::Drawing::Size(292, 266);
    			this->tabControl1->TabIndex = 0;
    			this->tabControl1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::tabControl1_SelectedIndexChanged);
    			// 
    			// tabPage1
    			// 
    			this->tabPage1->Location = System::Drawing::Point(4, 22);
    			this->tabPage1->Name = L"tabPage1";
    			this->tabPage1->Padding = System::Windows::Forms::Padding(3);
    			this->tabPage1->Size = System::Drawing::Size(284, 240);
    			this->tabPage1->TabIndex = 0;
    			this->tabPage1->Text = L"tabPage1";
    			this->tabPage1->UseVisualStyleBackColor = true;
    			// 
    			// tabPage2
    			// 
    			this->tabPage2->Location = System::Drawing::Point(4, 22);
    			this->tabPage2->Name = L"tabPage2";
    			this->tabPage2->Padding = System::Windows::Forms::Padding(3);
    			this->tabPage2->Size = System::Drawing::Size(192, 74);
    			this->tabPage2->TabIndex = 1;
    			this->tabPage2->Text = L"tabPage2";
    			this->tabPage2->UseVisualStyleBackColor = true;
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Controls->Add(this->tabControl1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->tabControl1->ResumeLayout(false);
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
    	private: System::Void tabControl1_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) 
    			 {
    				 if(tabControl1->SelectedTab->Name == "tabPage2")
    				 {
    					 Form1->Size::set(System::Drawing::Size::Size(365, 397));
    				 }
    			 }
    	};
    }
    

    Vielleicht hilfts ja 🙂



  • Ersetze mal dein Form1 durch this

    this->Size::set(System::Drawing::Size::Size(365, 397));
    


  • Woohoo es funktioniert!

    1000 dank 😃


Anmelden zum Antworten