2013-01-02 18 views
5

Bir panelin arka rengini linux (PCLinuxOS) altında art arda tekrar tekrar değiştirmesi beklenen bir test programı oluşturdum, ama gerçekten çok iyi çalışmıyor. Ya panellerin arka plan rengini sadece bir şeye tıkladıktan sonra ya da bir winus'u farz ederseniz ya da durduğunda ya da program kısa bir süre çalıştıktan sonra tamamen çöker. Belki zaman aralığı çok kısa veNeden winform paneli yalnızca fare veya fare kapanı olduğunda güncellenir?

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

Yalnızca tıklatma işleyicisi altında zamanlayıcıyı etkinleştirdiğiniz için formu tıklattığınızda çalışır. Panellerin hemen yanıp sönmesini istiyorsanız, yapıcıdaki zamanlayıcıyı etkinleştirin (veya başlatın). Ve farenin üzerine aldığın hata nedir? Herhangi bir yerde hiçbir fare-işleyici görmüyorum .. – nawfal

+0

@nawfal, Zamanlayıcı başlatıldığında veya düğmeyi tıklatarak etkinleştirildikten sonra, panel arka renk güncelleştirilmez, ancak sadece fare imlecinizi bir düğmenin üzerine getirdiğinizde ve/veya veya zamanlayıcı etkin olsa bile düğmeye veya winform araç çubuğuna tıklayın. Diğer zamanlarda sadece oturur bir şey yoktur. Ancak, aynı programı alıp beklendiği gibi çalıştığı pencerelerde çalıştırabilirim. – ThN

+0

Ancak, aynı programı alıp beklendiği gibi çalıştığı pencerelerde çalıştırabilirim. Evet, olayımda fare yok. Program, sadece winform'a bir şey yaptığınızda, yeniden boyamak veya yenilemek için WM_Paint mesaj bayrağını gönderiyormuş gibi davranıyor. – ThN

cevap

0

:

İşte enter image description here

bunun arkasında kod şudur: Burada

winform 2 paneller, bir düğme ve bir zamanlayıcı ile böyle görünüyor renkler çok hızlı değişiyor mu?

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. 
İlgili konular