Inquiridor
Problemas básicos VS2003 - Iniciante.

Pergunta
-
Bom dia , estou com problemas no VS2003, estou utilizando o Windows Forms e não estou conseguindo fazer chamar outro form quando clico num botão, gostaria de saber se vcs poderiam me ajudar, pois no VC++6 era bem mais fácil, e pelo que vi parece que terei que declarar um ponteiro, usar a função SHOW(), mas não consegui entender certinho, será que alguém poderia me dar umas dicas, passar um tutorial de windows forms, outra coisa eu não consegui desenhar um form dentro de outro form, como se fosse um datagrid dentro de um form, isso é possível???? Por favor me ajudem......Obrigado.
Todas as Respostas
-
mps,
Em C# pode ser assim:
SeuForm f = new SeuForm();
f.Show();E em VB.Net:
Dim f As New SeuForm()
f.Show()Abraços,
Francisco
Ok,Computer - http://thespoke.net/blogs/fbcjunior/default.aspx -
-
mps,
Seria algo como:
SeuForm *seufrm = new SeuForm;
seufrm->Show();
Abraços,
Francisco
Ok,Computer - http://thespoke.net/blogs/fbcjunior/default.aspx -
-
mps,
O comum neste caso é usar aplicativos MDI:
http://msdn2.microsoft.com/en-us/library/xyhh2e7e.aspx
Mas você até pode usar um form ou outro container como um panel ou groupbox para hospedar um segundo form, pois um form deriva de Control. Então seria só você instanciar o form e usar o método Add da coleção Controls do container para adicioná-lo. É exatamente o processo descrito abaixo para adicionar um controle a um form programaticamente:
http://msdn2.microsoft.com/en-us/library/0h5y8567.aspx
Abraços,
Francisco
Ok,Computer - http://thespoke.net/blogs/fbcjunior/default.aspx -
Francisco, ai segui o que vc me passou, instaciar o form dentro de outro form, ele chega até compilar, mas ao carregar aparece uma msg de erro
"An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: Cannot add a top level control to a control."
Então se eu tiro a instaciação do form de dentro, funciona normal. Segue o código:
#pragma
once#include
"Form32.h" -->Inclui aqui o form que crieiusing
namespace System;using
namespace System::ComponentModel;using
namespace System::Collections;using
namespace System::Windows::Forms;using
namespace System::Data;using
namespace System::Drawing;namespace
ProjetoTeste1{
/// <summary>
/// Summary for Form2
///
/// 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 __gc class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{
InitializeComponent();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::Label * label1;
private: System::Windows::Forms::RadioButton * radioButton1;
private: System::Windows::Forms::RadioButton * radioButton2;
private: System::Windows::Forms::RadioButton * radioButton3;
private: System::Windows::Forms::RadioButton * radioButton4;
private: System::Windows::Forms::TextBox * tbeixox;
private: System::Windows::Forms::TextBox * tbeixoy;
private: System::Windows::Forms::Button * button1;
private: System::Windows::Forms::Button * btnsair2d;
private: System::Windows::Forms::Label * lbleixox;
private: System::Windows::Forms::Label * lbleixoy;
private: System::Windows::Forms::Form * Form3; --->DECLAREI AQUI...
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container* components;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->label1 = new System::Windows::Forms::Label();
this->radioButton1 = new System::Windows::Forms::RadioButton();
this->radioButton2 = new System::Windows::Forms::RadioButton();
this->radioButton3 = new System::Windows::Forms::RadioButton();
this->radioButton4 = new System::Windows::Forms::RadioButton();
this->tbeixox = new System::Windows::Forms::TextBox();
this->tbeixoy = new System::Windows::Forms::TextBox();
this->button1 = new System::Windows::Forms::Button();
this->btnsair2d = new System::Windows::Forms::Button();
this->lbleixox = new System::Windows::Forms::Label();
this->lbleixoy = new System::Windows::Forms::Label();
this->Form3 = new System::Windows::Forms::Form(); --->INSTANCIEI AQUI..
this->SuspendLayout();
//
// label1
//
this->label1->Font = new System::Drawing::Font(S"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
this->label1->Location = System::Drawing::Point(16, 24);
this->label1->Name = S"label1";
this->label1->Size = System::Drawing::Size(216, 23);
this->label1->TabIndex = 0;
this->label1->Text = S"Selecione o que deseja fazer:";
this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//
// radioButton1
//
this->radioButton1->Location = System::Drawing::Point(16, 72);
this->radioButton1->Name = S"radioButton1";
this->radioButton1->TabIndex = 1;
this->radioButton1->Text = S"radioButton1";
//
// radioButton2
//
this->radioButton2->Location = System::Drawing::Point(16, 96);
this->radioButton2->Name = S"radioButton2";
this->radioButton2->TabIndex = 2;
this->radioButton2->Text = S"radioButton2";
//
// radioButton3
//
this->radioButton3->Location = System::Drawing::Point(16, 120);
this->radioButton3->Name = S"radioButton3";
this->radioButton3->TabIndex = 3;
this->radioButton3->Text = S"radioButton3";
//
// radioButton4
//
this->radioButton4->Location = System::Drawing::Point(16, 144);
this->radioButton4->Name = S"radioButton4";
this->radioButton4->TabIndex = 4;
this->radioButton4->Text = S"radioButton4";
//
// tbeixox
//
this->tbeixox->Location = System::Drawing::Point(64, 240);
this->tbeixox->Name = S"tbeixox";
this->tbeixox->Size = System::Drawing::Size(48, 20);
this->tbeixox->TabIndex = 6;
this->tbeixox->Text = S"";
//
// tbeixoy
//
this->tbeixoy->Location = System::Drawing::Point(64, 264);
this->tbeixoy->Name = S"tbeixoy";
this->tbeixoy->Size = System::Drawing::Size(48, 20);
this->tbeixoy->TabIndex = 7;
this->tbeixoy->Text = S"";
//
// button1
//
this->button1->Location = System::Drawing::Point(53, 304);
this->button1->Name = S"button1";
this->button1->Size = System::Drawing::Size(80, 23);
this->button1->TabIndex = 8;
this->button1->Text = S"button1";
//
// btnsair2d
//
this->btnsair2d->Location = System::Drawing::Point(54, 344);
this->btnsair2d->Name = S"btnsair2d";
this->btnsair2d->Size = System::Drawing::Size(80, 23);
this->btnsair2d->TabIndex = 9;
this->btnsair2d->Text = S"&Sair";
this->btnsair2d->Click += new System::EventHandler(this, btnsair2d_Click);
//
// lbleixox
//
this->lbleixox->Font = new System::Drawing::Font(S"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
this->lbleixox->Location = System::Drawing::Point(16, 244);
this->lbleixox->Name = S"lbleixox";
this->lbleixox->Size = System::Drawing::Size(40, 16);
this->lbleixox->TabIndex = 10;
this->lbleixox->Text = S"Eixo X";
//
// lbleixoy
//
this->lbleixoy->Font = new System::Drawing::Font(S"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, (System::Byte)0);
this->lbleixoy->Location = System::Drawing::Point(16, 267);
this->lbleixoy->Name = S"lbleixoy";
this->lbleixoy->Size = System::Drawing::Size(40, 16);
this->lbleixoy->TabIndex = 11;
this->lbleixoy->Text = S"Eixo Y";
//
//Form3 --->AQUI EU NÃO SEI SE PRECISA DISSO OU, SE IMPORTA AS INFORMAÇÕES
// DENTRO DO HEANDLER FORM3.H
this->Form3->Location = System::Drawing::Point(258, 10);
this->Form3->Name = S"Form3";
this->Form3->Size = System::Drawing::Size(350, 358);
this->Form3->TabIndex = 12;
//
// Form2
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(614, 372);
this->Controls->Add(this->lbleixoy);
this->Controls->Add(this->lbleixox);
this->Controls->Add(this->btnsair2d);
this->Controls->Add(this->button1);
this->Controls->Add(this->tbeixoy);
this->Controls->Add(this->tbeixox);
this->Controls->Add(this->radioButton4);
this->Controls->Add(this->radioButton3);
this->Controls->Add(this->radioButton2);
this->Controls->Add(this->radioButton1);
this->Controls->Add(this->label1);
this->Controls->Add(this->Form3); ---->CHAMO PRA DENTRO DO FORM2
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle; -->MOSTRA
this->MaximizeBox = false; DEPOIS DA MSG DE ERRO ESTA LINHA COMO
this->Name = S"Form2"; ERRO NO ESTILO FIXEDSINGLE
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = S"Tela 2D";
this->Load += new System::EventHandler(this, Form2_Load);
this->ResumeLayout(false);
}
Onde estou errando???? Se vc puder me ajudar agradeco.......
E desculpa por colocar todo esse codigo........
Obrigado.
Vlw.......
-
Olá,
Tente mudar a propriedade TopLevel do Form3 para False antes de chamar o método Add da coleção Controls de seu form.
Abraços,
Francisco
OK, Computer - http://thespoke.net/blogs/fbcjunior/default.aspx -
Ai Francisco, obrigado pela dica, mas uma coisa, vc sabe me informar o porque essa linha é refenciada como erro??
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
Não entendi, se vc puder me informar agradeço.
Obrigado.
-
Qual a mensagem de erro?
Abraços,
Francisco
Ok,Computer - http://thespoke.net/blogs/fbcjunior/default.aspx -
Então eu tentei mudar a propriedade do TopLevel do Form 3 para False, mas mesmo assim aparece a mesma msg de erro, então tentei mudar para False a propriedade do TopLevelControl, mas apareceu uma msg de erro, então não consegui, será que vc não poderia fazer um exemplo pra mim e me passar o fonte, pois não estou conseguindo, ou senã, vc me falar se tem alguma outra forma de fazer o seguinte:
Estou trabalhando com a API Directx, então preciso montar uma janela dentro do form para desenhar com o directx, o programa vai desenhar vetores 3d em tempo real. Eu entro com os valores e os vetores vão atualizando assim que eu confirmar, são vetores 3D, Por isso preciso de 2 Forms, um para ter os botões e tal, e outro "atachado" dentro deste primeiro form (como se fosse um control mesmo), para fazer os desenhos com o directx, e esse form precisa ser dessa forma, para se o form principal for minimizado este segundo form (form dos vetores) seja minimizado proporcionalmente com o form principal. Não sei se vc me entendeu, mas me da uma força.....
Obrigado.
Marcus Paulo.
-
Marcus,
Infelizmente eu não tenho o Visual C++ instalado, eu trabalho com VB.Net e Visual C#. Se quiser algum exemplo nestas linguagens é só avisar.
Abraços,
Francisco
Ok,Computer - http://thespoke.net/blogs/fbcjunior/default.aspx -
-
Marcus,
Por exemplo, coloque no evento Load de um form o seguinte código:
Form f = new Form();
f.TopLevel = false;
this.Controls.Add(f);
f.Show();Abraços,
Francisco
Ok,Computer - http://thespoke.net/blogs/fbcjunior/default.aspx -
Ai Francisco deu certo o que vc me passou, só muda no C++ é o operador SETA (->) no lugar dos PONTOS(.), mas depois que coloco o trecho do código que vc me passou, se compilar funciona, mas quando vou na tela de design, aparece um erro ao inves de aparece um form, então tentei fazer com o C# e deu certo, aparece um Form dentro de outro, o que será que pode estar ocorrendo, pq se continuar assim eu terei que colocar todos os control "na mão" no form de dentro, a msg de erro que aparece é a seguinte:
An error ocurred while loading the document. Fix the error, and then try loading the document again. The error message follows:
MCppCodeDomParse Error:
Então Francisco vc sabe do que se trata??? Aproveitando o embalo vc pode me explicar como eu crio uma variavel do tipo int publica, onde consigo acessar e alter em qualque parte do meu código, é que preciso toda vez que clicar num botão (evento Click), incrementar o contador, e depois no código de um outro FORM verificar quantas vezes esse botão foi clicado, vc poderia me explicar??? E também como faço para checar um radiobutton? utilizei a função Checked e não consegui...........agradeço se vc puder me ajudar nisso.....
Obrigado.
Marcus Paulo.
-
Marcus,
Bom, eu não trabalho com C++, parece um erro localizado, acho que vocë pode ter mais sucesso se postá-lo no Forum de Visual C++ ou no Newsgroup de C++.
Para tornar disponível está variável int que você citou, crie uma variável de classe pública ou uma propriedade de classe pública em uma classe qualquer do seu aplicativo. Em C# seria fazer uso da palavra chave Static.
public static int nome-da-variavel;
Para checar um RadioButton é só passar para o True o seu valor mesmo.
Eu acho que o pessoal dos grupos que lhe citei podem lhe ajudar melhor com suas dúvidas, infelizmente eu não trabalho com C++.
Abraços,
Francisco
OK, Computer - http://thespoke.net/blogs/fbcjunior/default.aspx