|
Timer를 이용해서 Form2->ProgressBar1을 조작해 봤습니다.
Form2가 Form1의 작업 진행 상황을 보이는 용도라면 ShowModal()보단
Show()가 더 적당할 것 같아 Form2의 FormStyle을 fsStayOnTop으로 하여
Form2가 언제나 보이도록 한 후 Form2->Show()로 처리하도록 하였습니다.
글구 ... Form2는 Project/Option Menu의 Forms tab에서 Available Forms로
이동시킨후 실행해 주세요.
즐거운 하루되세요.
=========
Unit1.Cpp
=========
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
Form2 = NULL;
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1( void )
{
if( Form2 != NULL ) {
delete Form2;
Form2 = NULL;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if( Form2 == NULL ) {
Form2 = new TForm2( this );
Form2->FormStyle = fsStayOnTop;
}
Form2->Show();
Form2->ProgressBar1->Position = Form2->ProgressBar1->Min;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if( Form2 != NULL ) {
if( Form2->ProgressBar1->Position < Form2->ProgressBar1->Max ) {
Form2->ProgressBar1->Position = Form2->ProgressBar1->Position + 1;
}
else {
Form2->Hide();
}
}
}
//---------------------------------------------------------------------------
=======
Unit1.H
=======
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TTimer *Timer1;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Timer1Timer(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
__fastcall ~TForm1( void );
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
=========
Unit1.DFM
=========
object Form1: TForm1
Left = 355
Top = 227
Width = 783
Height = 540
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 40
Top = 20
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object Timer1: TTimer
Interval = 100
OnTimer = Timer1Timer
Left = 124
Top = 20
end
end
=========
Unit2.Cpp
=========
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
=======
Unit2.h
=======
//---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TForm2 : public TForm
{
__published: // IDE-managed Components
TProgressBar *ProgressBar1;
private: // User declarations
public: // User declarations
__fastcall TForm2(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 *Form2;
//---------------------------------------------------------------------------
#endif
=========
Unit2.DFM
=========
object Form2: TForm2
Left = 307
Top = 157
Width = 354
Height = 129
Caption = 'Form2'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ProgressBar1: TProgressBar
Left = 4
Top = 40
Width = 337
Height = 16
Min = 0
Max = 100
TabOrder = 0
end
end
--------------------------------------------------------------------
볼로 님이 쓰신 글 :
: Form A에서 선택한 데이터틀 순서데로 출력하는 동안
:
: ProgressBar를 가진 Form B를 띄워 진행 상태를 나타내려 합니다.
:
: 그런데 Form B를 ShowModal()로하면 FormA와 FormB가 서로 데이터를 주고 받지 못하는 군요.
:
: modaless로 할 경우에는 정상적으로 동작합니다만.
:
: 어떻게하면 ShowModal()로 띄우고 Form A와 Form B가 서로 데이터를 주고 받을 수 있을 까요?
|