Click here to Skip to main content
15,891,905 members
Home / Discussions / C#
   

C#

 
QuestionRe: Add controls to a tab page at run-time Pin
CodingLover26-Aug-08 19:53
CodingLover26-Aug-08 19:53 
AnswerRe: Add controls to a tab page at run-time Pin
Mycroft Holmes26-Aug-08 22:07
professionalMycroft Holmes26-Aug-08 22:07 
GeneralRe: Add controls to a tab page at run-time Pin
CodingLover26-Aug-08 22:43
CodingLover26-Aug-08 22:43 
GeneralRe: Add controls to a tab page at run-time Pin
Mycroft Holmes26-Aug-08 22:54
professionalMycroft Holmes26-Aug-08 22:54 
GeneralRe: Add controls to a tab page at run-time Pin
michael@cohen26-Aug-08 23:18
michael@cohen26-Aug-08 23:18 
Questionproblem with the text box Pin
Preeti197926-Aug-08 19:14
Preeti197926-Aug-08 19:14 
AnswerRe: problem with the text box Pin
AhsanS26-Aug-08 19:43
AhsanS26-Aug-08 19:43 
QuestionGdi+ Memory Leak >Scrolling text Pin
michael@cohen26-Aug-08 19:06
michael@cohen26-Aug-08 19:06 
Hey Guys
a few days ago i made a custom control that uses GDI+.
after playing this control on the screen for 4 hours+ the cpu is getting 50% more Work
and Memory Keep Leaking ... after that the text is moving very slow and so on...

Here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using ScreenerViewer.BL.NewsBar;
namespace ScreenerViewer
{

    public partial class NewsBar : Control
    {
        //timer 
        Timer t = new Timer();
        //position the text
        int Position;
        //normall mode text
        StringWriter SdisplayNormalMode = null;
        //Flicker Mode Text
        StringWriter SdisplayFlickerMode = null;
        //Separate the Text
        string sSeparatesign = " * ";
        //Use it for Rest Position
        bool bRestPosition = false;
        // Backround Color For NormalMode
        Brush Backroundbrush = Brushes.Red;
        //Backround Color For Normal mode
        Brush BackroundFlickBrush = Brushes.Yellow;
        //Font color for flickermode
        Brush FontFlickerBrush =Brushes.Red;
        //counter for color change in flicker mode
        int iColorChange = 0;
        //first run of bar
        bool bFirstRun = false;
        
        Font TextFont = new Font(new FontFamily("arial"), 60);
        //Drawing the Point of the text
        PointF TextPoint = new PointF();
        private bool _bFilckerMode;
        public bool bFilckerMode
        {
            get { return _bFilckerMode; }
            set { _bFilckerMode = value; }
        }
	
        public NewsBar()
        {
            
            InitializeComponent();
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);

            SdisplayNormalMode =  new StringWriter();
            t.Interval = 10;
            t.Enabled = true;
            t.Tick += new EventHandler(t_Tick);
            Position = 0;
            bFirstRun = true;
            
        }

        void t_Tick(object sender, EventArgs e)
        {
          Position+=2;
          Invalidate();
         // Update();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            
            if (!this.bFilckerMode)
            {
                   //NormalMode
                    pe.Graphics.FillRectangle(Backroundbrush,0,0,this.ClientSize.Width,ClientSize.Height);
                    
                    SizeF stringSize = pe.Graphics.MeasureString(SdisplayNormalMode.ToString(),TextFont);
                    if (Position > ClientSize.Width)
                    {
                        Position =Convert.ToInt32( -1 * stringSize.Width);
                    }
                    // first run
                    if (Position == 0 && bFirstRun)
                    {
                        Position = Convert.ToInt32(-1 * stringSize.Width);
                    }
                    //Setting the Position of the text
                    TextPoint.X = Position;
                    TextPoint.Y = 0;
                    //Drawing the Text
                    pe.Graphics.DrawString(SdisplayNormalMode.ToString(), TextFont, Brushes.White, TextPoint);
                    
                  
            }
            else
            {
                //Flicker Mode

                //Changing Color Of backRound and Text
                if (iColorChange==20)
                {
                    if (BackroundFlickBrush == Brushes.Yellow)
                    {
                        BackroundFlickBrush = Brushes.Red;
                        FontFlickerBrush = Brushes.Yellow;
                    }
                    else
                    {
                        BackroundFlickBrush = Brushes.Yellow;
                        FontFlickerBrush = Brushes.Red;
                    }
                    iColorChange = 0;
                }
                iColorChange++;
               //Filling Rectangle with Color
                pe.Graphics.FillRectangle(BackroundFlickBrush, 0, 0, this.ClientSize.Width, ClientSize.Height);
                
                
                SizeF stringSize = pe.Graphics.MeasureString(SdisplayFlickerMode.ToString(), TextFont);
                if (Position == 0&&bFirstRun)
                {
                    Position = Convert.ToInt32(-1 * stringSize.Width);
                }
                if (Position > ClientSize.Width)
                {
                    Position = Convert.ToInt32(-1 * stringSize.Width);
                    bFilckerMode = false;
                    
                }
              //Reset Position of Text 
                if (bRestPosition)
                {
                    Position = Convert.ToInt32(-1 * stringSize.Width);
                }
                bRestPosition = false;
                //Drawing the Text
                pe.Graphics.DrawString(SdisplayFlickerMode.ToString(), TextFont, FontFlickerBrush, TextPoint);
                if (!bFilckerMode)
                {
                    SdisplayFlickerMode = null;
                }
            }
            bFirstRun = true;
            base.OnPaint(pe);
            
        }
        //Displaying Normal Mode Text
        public void DisplayListNormalMode(string[] Smsgdisplay) 
        {
            if (Smsgdisplay.Length > 0)
            {
                foreach (string msg in Smsgdisplay)
                {
                    SdisplayNormalMode.Write(msg + sSeparatesign); 
                }
            }
        }
        //Displaying Flicker Mode Text With Selected Sound
        public void DisplayListFlickerMode(BL.NewsBar.Flickeritem[] SFdisplay) 
        {
            SdisplayFlickerMode = new StringWriter();
            this.bFilckerMode = true;
            bRestPosition = true;
            string[] SoundFiles=null;
            if (SFdisplay.Length > 0 )
            {
                SoundFiles= new string[SFdisplay.Length];
                int index=0;
                foreach (Flickeritem msg in SFdisplay)
                {
                    SdisplayFlickerMode.Write(msg.Msg + sSeparatesign);  
                    SoundFiles[index]=msg.SoundPath;
                    index++;
                }
            }
            PlaySound sound = new PlaySound(SoundFiles);
            sound.PlayMyList();
           
            
        }

        }
 
    }

AnswerRe: Gdi+ Memory Leak >Scrolling text Pin
leppie26-Aug-08 22:00
leppie26-Aug-08 22:00 
GeneralRe: Gdi+ Memory Leak >Scrolling text Pin
Mycroft Holmes26-Aug-08 22:12
professionalMycroft Holmes26-Aug-08 22:12 
GeneralRe: Gdi+ Memory Leak >Scrolling text Pin
leppie26-Aug-08 22:19
leppie26-Aug-08 22:19 
GeneralRe: Gdi+ Memory Leak >Scrolling text Pin
michael@cohen26-Aug-08 22:58
michael@cohen26-Aug-08 22:58 
QuestionWindows Servce in windows application Problem Pin
idreesbadshah26-Aug-08 18:16
idreesbadshah26-Aug-08 18:16 
AnswerRe: Windows Servce in windows application Problem Pin
Ashfield26-Aug-08 21:10
Ashfield26-Aug-08 21:10 
GeneralRe: Windows Servce in windows application Problem Pin
idreesbadshah26-Aug-08 22:17
idreesbadshah26-Aug-08 22:17 
GeneralRe: Windows Servce in windows application Problem Pin
Ashfield27-Aug-08 2:52
Ashfield27-Aug-08 2:52 
Question.Net Framework version issue Pin
George_George26-Aug-08 16:52
George_George26-Aug-08 16:52 
AnswerRe: .Net Framework version issue Pin
Brij26-Aug-08 17:54
mentorBrij26-Aug-08 17:54 
GeneralRe: .Net Framework version issue Pin
George_George26-Aug-08 18:06
George_George26-Aug-08 18:06 
AnswerRe: .Net Framework version issue Pin
N a v a n e e t h26-Aug-08 17:54
N a v a n e e t h26-Aug-08 17:54 
GeneralRe: .Net Framework version issue Pin
George_George26-Aug-08 18:04
George_George26-Aug-08 18:04 
AnswerRe: .Net Framework version issue Pin
Abhijit Jana26-Aug-08 17:56
professionalAbhijit Jana26-Aug-08 17:56 
GeneralRe: .Net Framework version issue Pin
George_George26-Aug-08 18:05
George_George26-Aug-08 18:05 
AnswerRe: .Net Framework version issue Pin
Scott Dorman26-Aug-08 18:33
professionalScott Dorman26-Aug-08 18:33 
GeneralRe: .Net Framework version issue Pin
George_George26-Aug-08 19:17
George_George26-Aug-08 19:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.