2013-01-02 2 views
5

필자는 linux (PCLinuxOS)에서 패널의 배경색을 반복적으로 바꿔야하는 테스트 프로그램을 만들었지 만, 실제로 제대로 작동하지는 않습니다. 어느 쪽인가를 클릭했을 때만, 패널의 배경색을 갱신합니다. 또는, winform를 mouseover 해, 정지하면 (자), 잠시 실행 한 뒤, 프로그램이 모두 크래쉬합니다. 어쩌면 타이머 간격이 너무 짧고마우스 오버 또는 마우스 클릭시 winform 패널 만 업데이트되는 이유는 무엇입니까?

namespace TestIndicator; 

interface 

uses 
    System.Drawing, 
    System.Collections, 
    System.Collections.Generic, 
    System.Windows.Forms, 
    System.ComponentModel; 

type 
    /// <summary> 
    /// Summary description for MainForm. 
    /// </summary> 
    MainForm = partial class(System.Windows.Forms.Form) 
    private 
    method d_Click(sender: System.Object; e: System.EventArgs); 
    method timer1_Tick(sender: System.Object; e: System.EventArgs); 
    protected 
    method Dispose(disposing: Boolean); override; 
    public 
    constructor; 
    end; 

var 
    TurnOnRx, TurnOnTx:Boolean; 

implementation 

{$REGION Construction and Disposition} 
constructor MainForm; 
begin 
    // 
    // Required for Windows Form Designer support 
    // 
    InitializeComponent(); 

    // 
    // TODO: Add any constructor code after InitializeComponent call 
    // 
    TurnOnRx := true; 
    TurnOnTx := true; 
end; 

method MainForm.Dispose(disposing: Boolean); 
begin 
    if disposing then begin 
    if assigned(components) then 
     components.Dispose(); 

    // 
    // TODO: Add custom disposition code here 
    // 
    end; 
    inherited Dispose(disposing); 
end; 
{$ENDREGION} 

method MainForm.d_Click(sender: System.Object; e: System.EventArgs); 
begin 
    timer1.Enabled := not timer1.Enabled; 
end; 

method MainForm.timer1_Tick(sender: System.Object; e: System.EventArgs); 
begin 
    if TurnOnTx then 
    begin 
     TurnOnTx:=false; 
     TxLight.BackColor := Color.Red; 
    end 
    else 
    begin 
     TurnOnTx:=true; 
     TxLight.BackColor := Color.black; 
    end; 

    if TurnOnRx then 
    begin 
     TurnOnRx := false; 
     RxLight.BackColor := Color.Lime; 
    end 
    else 
    begin 
     TurnOnRx := true; 
     RxLight.BackColor := Color.Black; 
    end; 
end; 

end. 
+0

클릭 처리기에서만 타이머를 사용하도록 설정했기 때문에 양식을 클릭 할 때만 작동합니다. 패널을 바로 깜박 거리려면 생성자에서 타이머를 활성화 (또는 시작)하십시오. 마우스 오버시 발생하는 오류는 무엇입니까? 어쨌든 아무 마우스 오버 핸들러도 보지 못했습니다. – nawfal

+0

@nawfal, 타이머를 시작하거나 버튼을 클릭하여 활성화하면 패널 백 컬러가 업데이트되지 않지만 마우스 포인터를 버튼 위로 이동하거나/또는 타이머가 활성화되어 있어도 단추 또는 winform 도구 모음을 클릭하십시오. 그저 거기 앉아있는 다른 시간은 아무것도하지 않습니다. 그러나, 나는이 동일한 프로그램을 가져 와서 예상대로 작동하는 창에서 실행할 수 있습니다. – ThN

+0

그러나 나는이 동일한 프로그램을 가져 와서 예상대로 작동하는 창에서 실행할 수 있습니다. 예, 마우스 오버 이벤트가 없습니다. Winform에 무언가를 할 때 WM_Paint 메시지 플래그를 다시 그리거나 새로 고치는 것처럼 프로그램이 작동하는 것입니다. – ThN

답변

0

:

여기 enter image description here

가 뒤에 코드입니다 : 여기

은의 WinForm 2 개 패널 버튼과 타이머 모습입니다 색상이 너무 빠르게 변하는가?

namespace TestIndicator; 
interface 
uses 
    System.Drawing, 
    System.Collections, 
    System.Collections.Generic, 
    System.Windows.Forms, 
    System.ComponentModel; 

type 
    /// <summary> 
    /// Summary description for MainForm. 
    /// </summary> 
    MainForm = partial class(System.Windows.Forms.Form) 
    private 
    method d_Click(sender: System.Object; e: System.EventArgs); 
    method timer1_Tick(sender: System.Object; e: System.EventArgs); 
    protected 
    method Dispose(disposing: Boolean); override; 
    public 
    constructor; 
    end; 

var 
    TurnOnRx, TurnOnTx:Boolean; 

implementation 

{$REGION Construction and Disposition} 
constructor MainForm; 
begin 
    // 
    // Required for Windows Form Designer support 
    // 
    InitializeComponent(); 

    // 
    // TODO: Add any constructor code after InitializeComponent call 
    // 
    TurnOnRx := true; 
    TurnOnTx := true; 

    timer1.Inverval := 1000; 
end; 

method MainForm.Dispose(disposing: Boolean); 
begin 
    if disposing then begin 
    if assigned(components) then 
     components.Dispose(); 

    // 
    // TODO: Add custom disposition code here 
    // 
    end; 
    inherited Dispose(disposing); 
end; 
{$ENDREGION} 

method MainForm.d_Click(sender: System.Object; e: System.EventArgs); 
begin 
    timer1.Enabled := not timer1.Enabled; 
end; 

method MainForm.timer1_Tick(sender: System.Object; e: System.EventArgs); 
begin 
    if TurnOnTx then 
    begin 
     TurnOnTx:=false; 
     TxLight.BackColor := Color.Red; 
    end 
    else 
    begin 
     TurnOnTx:=true; 
     TxLight.BackColor := Color.black; 
    end; 

    if TurnOnRx then 
    begin 
     TurnOnRx := false; 
     RxLight.BackColor := Color.Lime; 
    end 
    else 
    begin 
     TurnOnRx := true; 
     RxLight.BackColor := Color.Black; 
    end; 

    TxLight.Refresh(); 
    RxLight.Refresh(); 

    Application.DoEvents(); 
end; 

end.