2013-01-02 2 views
5

私は、パネルのバックカラーをlinux(PCLinuxOS)の下で繰り返し前後に変更するテストプログラムを作成しましたが、実際にはうまくいきません。それは、何かをクリックしたり、マウスオーバーでwinformをクリックしたときにのみ、パネルのバックカラーを更新するか、それが停止するか、少しだけ実行した後にプログラムが完全にクラッシュします。ここでマウスオーバーまたはマウスクリック時にwinformパネルのみが更新されるのはなぜですか?

はWinフォームは2枚のパネル、ボタンとタイマーでどのように見えるかです:ここでは

enter image description here

は、その背後にあるコードです:

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

しかし、私はこの同じプログラムを実行し、期待どおりに動作するウィンドウで実行できます。はい、マウスオーバーイベントはありません。プログラムは、WM_Paintメッセージフラグを再描画するか、winformに何かしかしないときに更新するように動作するように動作します。 – ThN

答えて

0

たぶんタイマー間隔が短すぎると、色が速すぎますか?

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. 
関連する問題