resmi pictureboxdamı göstermeliyim yada panel vs vs...
Nasıl yapabilirim
http://support.microsoft.com/kb/816181 adresinde aşağıdaki gibi kod buldum gerekli kısımları ekledim ama hata aldım. sadece butona tıklayınca image.JPEG dosyamın gösterilmesini istiyorum pictureboxda
#pragma once
namespace MyApplication
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Reflection;
/// <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 __gc class Form1 : public System::Windows::Forms::Form
{
private: Assembly *_assembly;
private: Stream *_imageStream;
private: StreamReader *_textStreamReader;
private: System::Windows::Forms::PictureBox * pictureBox1;
private: System::Windows::Forms::Button* button1;
private: System::Windows::Forms::TextBox* textBox1;
private: System::Windows::Forms::Button* button2;
public:
Form1(void)
{
InitializeComponent();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
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->pictureBox1 = new System::Windows::Forms::PictureBox();
this->button1 = new System::Windows::Forms::Button();
this->textBox1 = new System::Windows::Forms::TextBox();
this->button2 = new System::Windows::Forms::Button();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Location = System::Drawing::Point(8, 8);
this->pictureBox1->Name = S"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(280, 152);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->Location = System::Drawing::Point(8, 184);
this->button1->Name = S"button1";
this->button1->TabIndex = 1;
this->button1->Text = S"Show Image";
this->button1->Click += new System::EventHandler(this, button1_Click);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(96, 224);
this->textBox1->Name = S"textBox1";
this->textBox1->Size = System::Drawing::Size(184, 20);
this->textBox1->TabIndex = 2;
this->textBox1->Text = S"textBox1";
//
// button2
//
this->button2->Location = System::Drawing::Point(8, 224);
this->button2->Name = S"button2";
this->button2->TabIndex = 3;
this->button2->Text = S"Get Text";
this->button2->Click += new System::EventHandler(this, button2_Click);
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(292, 266);
this->Controls->Add(this->button2);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = S"Form1";
this->Text = S"Form1";
this->Load += new System::EventHandler(this, Form1_Load);
this->ResumeLayout(false);
}
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{
try
{
_assembly = Assembly::GetExecutingAssembly();
_imageStream = _assembly->GetManifestResourceStream(S"MyImage.bmp");
_textStreamReader = new StreamReader(_assembly->GetManifestResourceStream(S"MyTextFile.txt"));
}
catch(Exception *ex)
{
MessageBox::Show("Error accessing resources!",ex->Message);
}
}
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
try
{
pictureBox1->Image = new Bitmap(_imageStream);
}
catch(Exception *ex)
{
MessageBox::Show("Error creating image!",ex->Message);
}
}
private: System::Void button2_Click(System::Object * sender, System::EventArgs * e)
{
try
{
if(_textStreamReader->Peek() != 1)
{
textBox1->Text = _textStreamReader->ReadLine();
}
}
catch(Exception *ex)
{
MessageBox::Show("Error writing text!",ex->Message);
}
}
};
}
önce forma ımageList ekledim. sonra chose imagesden resmimi seçtim. index değeri 0 oldu.
sonra butonun click olayına
pictureBox1->Image=ımageList1->Images[0];
yazdım oldu bitti :D
Forum Yazılımı : vBulletin v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.