TI
Topics
21 Jul 2024, 04:41
234
5
14 Apr 2024, 14:23
265
0
Replies
tikahcm2
27 Jul 2024, 03:33
( Updated at: 28 Jul 2024, 06:43 )
RE: Creating a form in the plugin failed
PanagiotisCharalampous said:
Thanks for replying
Here is my code. (no error reported when compiling)
using System;
using System.Drawing;
using cAlgo.API;
using System.Threading;
using System.Windows.Forms;
using System.Media;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class CountDown : Robot
{
[Parameter("Alert On", DefaultValue = true)]
public bool paramAlertOn { get; set; }
[Parameter("Always On Top", DefaultValue = true)]
public bool paramOnTop { get; set; }
[Parameter("Sound File Path", DefaultValue = "C:\\Users\\theha\\OneDrive\\Documents\\cAlgo\\sound.wav")]
public string SoundFilePath { get; set; }
private Thread _thread;
private frmCandleCountdown _counter;
const string alertFile = @"C:\Users\theha\OneDrive\Documents\cAlgo\sound.wmp3";
protected override void OnStart()
{
Timer.Start(1);
_counter = new frmCandleCountdown(this, paramOnTop);
_thread = new Thread(() =>{ _counter.ShowDialog(); });
_thread.SetApartmentState(ApartmentState.STA);
_thread.Start();
}
protected override void OnTimer()
{
int cdMinutes = 14 - Time.Minute % 15;
int cdSeconds = 59 - Time.Second;
_thread = new Thread(() =>{ _counter.UpdateCounter(cdMinutes.ToString("00")+":"+cdSeconds.ToString("00"));});
_thread.SetApartmentState(ApartmentState.STA);
_thread.Start();
if (Time.Second==31 && paramAlertOn)
{
Notifications.PlaySound(SoundFilePath);
}
}
protected override void OnStop()
{
_thread = new Thread(() => {_counter.Close();});
_thread.SetApartmentState(ApartmentState.STA);
_thread.Start();
}
}
public partial class frmCandleCountdown : Form
{
private const string resourcePath = @"C:\Users\theha\OneDrive\Documents\cAlgo\";
CountDown caller;
bool alwaysOnTop = true;
public frmCandleCountdown(CountDown _caller, bool _alwaysOnTop)
{
alwaysOnTop = _alwaysOnTop;
caller = _caller;
InitializeComponent();
}
public void UpdateCounter(string _text)
{
lblCounter.Text = _text;
}
private void frmCandleCountdown_FormClosed(object sender, FormClosedEventArgs e)
{
caller.Stop();
}
private void frmCandleCountdown_Load(object sender, EventArgs e)
{
this.Icon = new Icon(resourcePath+"Countdown.ico");
this.TopMost = alwaysOnTop;
}
}
partial class frmCandleCountdown
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.lblCounter = new System.Windows.Forms.Label();
this.SuspendLayout();
this.lblCounter.Dock = System.Windows.Forms.DockStyle.Top;
this.lblCounter.Font = new System.Drawing.Font("Bahnschrift SemiBold", 33F, System.Drawing.FontStyle.Regular);
this.lblCounter.Location = new System.Drawing.Point(0, 0);
this.lblCounter.Name = "lblCounter";
this.lblCounter.Size = new System.Drawing.Size(39, 39);
this.lblCounter.TabIndex = 0;
this.lblCounter.Text = "00:00";
this.lblCounter.TextAlign = System.Drawing.ContentAlignment.TopCenter;
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.BackColor = System.Drawing.SystemColors.GrayText;
this.ClientSize = new System.Drawing.Size(39, 39);
this.Controls.Add(this.lblCounter);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 16.39F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "frmCandleCountdown";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Left = Screen.PrimaryScreen.Bounds.Width-139;
this.Text = "Candle Count Down";
this.TopMost = true;
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.frmCandleCountdown_FormClosed);
this.Load += new System.EventHandler(this.frmCandleCountdown_Load);
this.ResumeLayout(true);
}
#endregion
private System.Windows.Forms.Label lblCounter;
}
}
Please check why the plugin is not running./.
@tikahcm2
tikahcm2
28 Jul 2024, 15:48
RE: RE: RE: Creating a form in the plugin failed
How can I convert this cbot into a plugin?
thanks!
@tikahcm2