Exemple #1
0
        private void btnPreview_Click(object sender, EventArgs e)
        {
            DiskSpaceImageWriter writer;
            int imageWidth;
            int imageHeight;
            string fontName;
            float fontSize;
            string fontColour;
            Boolean showVolumeLabel;

            imageWidth = Convert.ToInt32(this.nudWidth.Value);
            imageHeight = Convert.ToInt32(this.nudHeight.Value);
            fontName = this.llFont.Text;
            fontSize = float.Parse(Convert.ToString(this.nudSize.Value));
            fontColour = this.llColour.Text;
            showVolumeLabel = this.cbxShowVolume.Checked;

            writer = new DiskSpaceImageWriter(imageWidth, imageHeight, fontName, fontSize, fontColour, "", showVolumeLabel);
            writer.RenderImage();

            this.pbImage.Image = writer.Image;
            this.pbImage.Width = imageWidth;
            this.pbImage.Height = imageHeight;

            this.Width = imageWidth + 33;
            this.Height = imageHeight + 116;
        }
        protected override void OnStart(string[] args)
        {
            // Setup logging
            this.log = new EventLog("Application");
            if (!EventLog.SourceExists("DiskSpaceImage"))
            {
                EventLog.CreateEventSource("DiskSpaceImage", "Application");
            }
            this.log.Source = "DiskSpaceImage";

            // Log the parameters used
            this.log.WriteEntry("Image size is " + ConfigurationManager.AppSettings["ImageWidth"] + "px by " + ConfigurationManager.AppSettings["ImageHeight"] + "px", EventLogEntryType.Information);
            this.log.WriteEntry("Image style is " + ConfigurationManager.AppSettings["FontName"] + " " + ConfigurationManager.AppSettings["FontSize"] + "em " + ConfigurationManager.AppSettings["FontColour"], EventLogEntryType.Information);
            this.log.WriteEntry("Image path is " + ConfigurationManager.AppSettings["ImageName"], EventLogEntryType.Information);

            // Initialise the writer object
            this.writer = new DiskSpaceImageWriter(
                   Convert.ToInt16(ConfigurationManager.AppSettings["ImageWidth"]),
                   Convert.ToInt16(ConfigurationManager.AppSettings["ImageHeight"]),
                   ConfigurationManager.AppSettings["FontName"],
                   float.Parse(ConfigurationManager.AppSettings["FontSize"]),
                   ConfigurationManager.AppSettings["FontColour"],
                   ConfigurationManager.AppSettings["ImageName"],
                   Convert.ToBoolean(ConfigurationManager.AppSettings["ShowVolumeLabel"]));

            // Write out the image
            this.OnTimedEvent(null, null);

            // Setup a timer to fire every X milliseconds
            this.t = new Timer((Convert.ToDouble(ConfigurationManager.AppSettings["TimerInterval"])));
            this.log.WriteEntry("Refresh interval set to " + this.t.Interval + "ms", EventLogEntryType.Information);
            this.t.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            this.t.AutoReset = true;
            this.t.Start();
        }