Erreur C2352 et évènements
Bonjour à tous,
j'ai récemment migrer de C++Builder 6 à Visual Studio 2005.
La gestion des évènements est différente mais le problème n'est pas là.
Dans le header de ma form (d'une Windows Forms Application), mes évènements sont bien en private etc....
Lorsque je veux appeler une fonction à l'intérieur d'un évènement, l'erreur C2352 (illegal call of non-static member function
) fait son apparition à l'appel de fonctions non statiques.
Autrement dit : je ne peux pas appeler de fonctions non statiques à l'intérieur de ma class Form.
Voici le code mon Form1.h.
La ligne où se produit l'erreur est l'appel du drawline.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#pragma once
namespace TEST {
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;
}
}
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::PictureBox^ pictureBox1;
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->button1 = (gcnew System::Windows::Forms::Button());
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// button1
//
this->button1->BackColor = System::Drawing::SystemColors::ActiveBorder;
this->button1->ForeColor = System::Drawing::SystemColors::ButtonShadow;
this->button1->Location = System::Drawing::Point(118, 32);
this->button1->Name = L"button1";
this->button1->RightToLeft = System::Windows::Forms::RightToLeft::No;
this->button1->Size = System::Drawing::Size(60, 26);
this->button1->TabIndex = 1;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = false;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// pictureBox1
//
this->pictureBox1->Location = System::Drawing::Point(43, 88);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(209, 159);
this->pictureBox1->TabIndex = 2;
this->pictureBox1->TabStop = false;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(292, 273);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->Opacity = 0.5;
this->pictureBox1->Image = this->pictureBox1->Image->FromFile(System::IO::Directory::GetCurrentDirectory() + "\\Image1.bmp");
TEST::Pen ^aPen = TEST::Pen(TEST::Color::AliceBlue);
// ERREUR //
TEST::Drawing::Graphics::DrawLine(aPen, 5,5, 40,40);
}
};
} |
Questions :
- Dans les évènements, on doit bien pouvoir appeler n'importe quelle fonction qu'elle soit statique ou non (ou comment résoudre ce problème ?
- Et est-ce que dans le header de la form on peut appeler des fonctions externes que l'on a codé ? ( ex : Fonctions.h -> dans le Form1.h : #include "Fonctions.h" -> utilisation de fonctions dans les évènements de Form1.h provenant de Fonctions.h)
J'espère que j'ai été assez clair :mrgreen: .
Merci à vous
problème d'affichage des lignes Drawline
J’ai essayé de dessiner des lignes après un événement button_click sur un Panel qui à une longueur variable (en fonction de mon input (fichier log) et qui peut dépasser 2000 ligne
Mais lorsque je compile et j’exécute je trouve que l’affichage des lignes n’est pas stable c'est-à-dire lorsque je déplace le scrollBar du panel pour voir la restes des lignes alors toutes les lignes disparue le même cas lorsque je déplace la fenêtre sous une autre fenêtre, comme si le programme est planté et ce n’est pas le cas.
J’ai changé l’événement par Panel_paint et ça roule mais un autre problème est apparu:
Lorsque je déplace le scrolleBar toutes les contenue de mon panel (des milliers des lignes et des labels) devient bizard et très lourd à afficher!
Aide moi s’il vous plais à résoudre ce problème c’est urgent!!