473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How do i make the text inside the control to move up like news feeder?

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12.     public partial class NewsControl : UserControl
  13.     {
  14.         String drawString;
  15.         public NewsControl()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void NewsControl_Paint(object sender, PaintEventArgs e)
  21.         {
  22.             // Create string to draw.
  23.             getText(drawString);
  24.             // Create font and brush.
  25.             Font drawFont = new Font("Arial", 8);
  26.             SolidBrush drawBrush = new SolidBrush(Color.Black);
  27.             // Create point for upper-left corner of drawing.
  28.             float x = 130.0F;
  29.             float y = 170.0F;
  30.             // Set format of string.
  31.             StringFormat drawFormat = new StringFormat();
  32.             drawFormat.FormatFlags = StringFormatFlags.DirectionRightToLeft;
  33.             // Draw string to screen.
  34.             e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
  35.         }
  36.  
  37.         public void getText(string getText)
  38.         {
  39.             drawString = getText;
  40.         }
  41.     }
  42. }
  43.  

This just show any text i enter in Form1 for example in form1 constructor i did:



newsControl1.getText("Hello");

And when im running my program i see Hello.

But now i want using For loop and timer i want that the word Hello to move inside the control up and go away up then return from down bottom again and foinf up again like a loop and each i add more text it will make new line and the seocnd line will go up after the first one and so on.

And i want it will show the control box borders i mean now i just see a text i need to see some borders box or something so the text wont look like it hang in the air.



You can see here on the right top as the page is loading how it should be how the text is moving up: http://www.ynet.co.il/home/0,7340,L-8,00.html



Thanks for help.
Jan 13 '11 #1

✓ answered by Samuel Jones

The problem that i could see with the original method was that you are redrawing the same object so many times per second from scratch. Which is why it flickers.

btw... if you change the timer's interval you can make it even slower...

But it is easy to adapt my code to your solution.

move your "float y = " outside of that method.
adjust the timer to read this:

Expand|Select|Wrap|Line Numbers
  1. private void timer1_Tick(object sender, EventArgs e)
  2.         {
  3.             y = y - jump;
  4.             if (y< = -20)
  5.                 y = this.Height + 20;
  6.             Refresh();
  7.         }
  8.  

7 2481
How similar are you trying to make it in comparison to the webpage? are you trying the little rotation as well?

I have managed to recreate your project but i need a little more insight.
Jan 13 '11 #2
Samuel it dosent have to be 100% like the it is in the webpage but the same idea.
The webpage was just example.
Ill make the frame around the text later and colors but the movement should be the same from down to up in a loop.

Thanks.
Jan 13 '11 #3
well if that is the case, can't you just use a moving label?

Reasons why.
  1. Labels have borders
  2. Labels are easy to change color
  3. Labels can have multiple lines
  4. Labels can be shifted easily
Jan 13 '11 #4
Samuel ok then with label that a good idea.
Jan 13 '11 #5
To do this, create a control (150x150 in size), add a label (called label1) roughly in the middle.

Try this for a solution:

Expand|Select|Wrap|Line Numbers
  1. public partial class customControl : UserControl
  2.     {
  3.         int jump = 0;
  4.  
  5.         public customControl()
  6.         {
  7.             InitializeComponent();
  8.         }
  9.  
  10.         public void startCustom()
  11.         {
  12.             timer1.Interval = 50;  // Timer Speed
  13.             jump = 10;             // Gap in pixels
  14.  
  15.             timer1.Start();
  16.         }
  17.  
  18.         private void timer1_Tick(object sender, EventArgs e)
  19.         {
  20.             label1.Location = new Point(label1.Location.X, label1.Location.Y - jump);
  21.         }
  22.  
  23.         private void label1_LocationChanged(object sender, EventArgs e)
  24.         {
  25.             if (label1.Location.Y <= -20)
  26.                 label1.Location = new Point(label1.Location.X, this.Height + label1.Height);
  27.         }
  28.     }

To use: call startCustom();
Jan 13 '11 #6
Samuel Working great.

Two questions please:

1. Not so critical now but lets say i wanted to use instead of label1 just paint event inside the control and write the text directly to the control with drawstring for example:

Expand|Select|Wrap|Line Numbers
  1. [C#] 
  2. public void DrawStringFloatFormat(PaintEventArgs e)
  3. {
  4. // Create string to draw.
  5. String drawString = "Sample Text";
  6. // Create font and brush.
  7. Font drawFont = new Font("Arial", 16);
  8. SolidBrush drawBrush = new SolidBrush(Color.Black);
  9. // Create point for upper-left corner of drawing.
  10. float x = 150.0F;
  11. float y =  50.0F;
  12. // Set format of string.
  13. StringFormat drawFormat = new StringFormat();
  14. drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
  15. // Draw string to screen.
  16. e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
  17. }
  18.  
So how can i use also timer to make this text to move like you did with the label? I mean instead the label using this.


2. I want to make the label now o move slowly up so i cahgned this variables values:

Expand|Select|Wrap|Line Numbers
  1. timer1.Interval = 50;
  2. jump = 1;
  3.  
So jump = 1; is the lowest i can get and its moving good but i think there are still some flickering i mean very small small jumps. Its not that much a problem to the eye but lets say i wanted to make it much smoother in this speed?


Thanks for helping.
Jan 13 '11 #7
The problem that i could see with the original method was that you are redrawing the same object so many times per second from scratch. Which is why it flickers.

btw... if you change the timer's interval you can make it even slower...

But it is easy to adapt my code to your solution.

move your "float y = " outside of that method.
adjust the timer to read this:

Expand|Select|Wrap|Line Numbers
  1. private void timer1_Tick(object sender, EventArgs e)
  2.         {
  3.             y = y - jump;
  4.             if (y< = -20)
  5.                 y = this.Height + 20;
  6.             Refresh();
  7.         }
  8.  
Jan 13 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Marco Simone | last post by:
Hi, I have form with four text box controls. 3 text box controls are bound to table A, and 4 text box control sums values in this 3 text boxes with formula in Control source. txtBox4=++ If I...
6
by: MLH | last post by:
Runtime error 13 - type mismatch. I get the above error when I create a text box control on a form named and I run the following code in a sub on that same form... If DLookup("", "tblUsers",...
0
by: Fred Heida | last post by:
Hi, I try to implement dragging (and dropping) of text inside a rtf control (similar as word i guess) I have set AllowdDrop = true and setup the handlers for DragDrop, DragOver, DragEnter. is...
3
by: Nick Haines | last post by:
I need to write my own custom text edit control.. but I'm not sure where to start - I've never written a custom control... the features I want are somewhat similar to the VS .Net text editor - text...
4
by: Devhead | last post by:
i have an delphi application that i'm converting over into c#. one of the controls on one of my forms is a rich text control. the text is saved as html to an sql server db. is there a winform text...
1
by: Paul | last post by:
Hi all, I'm making a custom control. I can set attributes to determine how the control is rendered, but I don't know how to access the text inside the tag. For example: <tagprefix:TestControl...
0
by: Paul_Madden via DotNetMonster.com | last post by:
I think this question could be answered in one word, either "No" or "Name-of- the-control". Am (still unfortunately :-)) having to use .NET 1.1 at work. Would like to display a simple text file...
11
by: giannis | last post by:
How can i refer to a form's textbox.text inside a SQL clause ? I know how is that in Access* but at VB i receive error. * SELECT FIELD1 FROM TABLE1 WHERE TABLE1.FIELD2=!.
2
by: amitp | last post by:
hi i'm using MS Word2003 for my VB application which is a report. The word documents contains tables and the cells inside the table contain some fields. My application replaces the field values with...
4
by: =?Utf-8?B?YWxiZXJ0b3Nvcmlh?= | last post by:
Hi everydoby! I have an issue, I have an static image, and I need to write text inside it in runtime, but I don't know how! I can't use absolute position in atributtes style. Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.