2013-01-02 56 views
5

मैंने एक टेस्ट प्रोग्राम बनाया है जिसे लिनक्स (पीसीएलिनक्सओएस) के तहत बार-बार पैनल के बैककलर को बदलना है, लेकिन यह वास्तव में बहुत अच्छी तरह से काम नहीं करता है। या तो यह केवल पैनलों के बैककलर को अपडेट करता है जब आप किसी चीज़ पर क्लिक करते हैं या Winform को माउसफ़ॉर्म करते हैं तो यह बंद हो जाता है या प्रोग्राम थोड़ी देर के लिए चलने के बाद पूरी तरह से क्रैश हो जाता है। हो सकता है कि टाइमर अंतराल बहुत छोटा है औरक्यों 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

हालांकि, मैं यह वही प्रोग्राम ले सकता हूं और इसे विंडोज़ पर चला सकता हूं जो अपेक्षा के अनुसार काम करता है। हाँ, मेरे पास घटना पर कोई माउस नहीं है। कार्यक्रम अभिनय कर रहा है जैसे यह केवल WM_Paint संदेश ध्वज को पुनर्निर्मित या ताज़ा करने के लिए भेज रहा है जब आप केवल Winform के लिए कुछ करते हैं। – 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.