Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a label that is moving in my form >> the label info is brought from table in my database ( news table)

the news shown in the label and moved but i want to split between the first news and the second wth a picture

how can i do that ,,,,, like news bar in tv channels

hope i find some hints or help

i have used thi code for moving and getting data from data base

C#
cmd = new SqlCommand("select *  from news ", fcon);
          if (fcon.State == ConnectionState.Open)
              fcon.Close();
          fcon.Open();
          rdr = cmd.ExecuteReader();
          while (rdr.Read())
          {
                news_news.Text += rdr[1].ToString()+shw_info.news_delimitter;//
         }

          rdr.Close();


moving label in timer tick

Quote:
if (l.Left > this.Width)
l.Left = 0;
else
l.Left = l.Left + 1;


i dont know where i can call my image as a splitter

is label my best control or should i use anther control

thanx in advance
Posted

You can't use a label - or at least not without a lot of faffing.

I would create my own UserControl, and write the text (and draw the images) in the Paint event - it's not complex, and it's probably going to look better than manually doing marquee on a labels text if only because you can select the speed in terms of pixels rather than characters, and it can be a lot smoother as a result - remember that most fonts are proportional, so "i" is a lot thinner than "W". If you marquee by character, then the speed varies according to what characters you are removing.
 
Share this answer
 
Comments
Ank_ush 9-Nov-13 1:07am    
You are right.
Quote:
thanks for ur answer
it seems to be the right one

i will try for the firt time to create my own user control and i will be back to tell u if it worked

thanx alot Original Griff
 
Share this answer
 
Comments
OriginalGriff 9-Nov-13 1:46am    
You're welcome!
BTW: Don't post replies as an Answer - if you use the "Reply" system, then it sends an email to the person you want to talk to (and people don't down vote you for posting "Not an answer"). That speeds up communication as they don't have to "check back" to see if you have replied.
eng.iris 9-Nov-13 14:39pm    
ok thanks for ur advice
i will then
i have created th contol as u said but all th news tha brought from the table are all before th image

the code i used to the control ( the user control contains a label and picturebox)


Quote:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication8
{
public partial class news_uc : UserControl
{
public news_uc()
{
InitializeComponent();
}
public string news_text
{
get { return news.Text; }
set { news.Text = value; Invalidate(); }
}
public Image img_news_delimetter
{
get { return img_delimetter.Image; }
set { img_delimetter.Image = value; Invalidate(); }
}
public string txt_news_delimetter
{
get { return text_delimiter.Text; }
set { text_delimiter.Text = value; Invalidate(); }

}


}
}


the code in the form

Quote:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication8
{
public partial class Form1 : Form
{
public SqlConnection fcon = new SqlConnection(@"Data Source=ME-PC\server;Initial Catalog=first_db;Integrated Security=True");
public SqlCommand cmd;
public SqlDataReader rdr;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

timer1.Enabled = true;
}
void marquee(news_uc l)
{
if (l.Left > this.Width)
l.Left = 0;
else
l.Left = l.Left + 1;
}

private void timer1_Tick(object sender, EventArgs e)
{
marquee(news_uc1);
fill_news();
}

private void fill_news()
{
cmd = new SqlCommand("select * from news where is_activated=1 order by news_date", fcon);
if (fcon.State == ConnectionState.Open)
fcon.Close();
fcon.Open();
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
news_uc1.news_text += rdr[1].ToString();//
}

rdr.Close();

}



}
}


mmmmmmmmmmmm where is the problem >>> to repeat my img after each news

thanks again
 
Share this answer
 
Comments
OriginalGriff 9-Nov-13 3:58am    
I wouldn't do it like that.
I would create a MarqueeElement class, which has a Text and an Image property, and then have a private List of MarqueeElement objects within my Marquee usercontrol (with Add and Remove methods)
I'd then display each Marquee element in turn rather than building up a string to display - that way, when an item is fresh, you just add it to the list, and when it is stale you just remove it - the control works out what it should be displaying at any particular time, rather than the Form that contains it. The form is then just responsible for loading items into the news "ticker" and can forget about it completely.
eng.iris 9-Nov-13 14:42pm    
how can i define my user contol as a list ??
OriginalGriff 9-Nov-13 14:59pm    
Don't.
Create a List as a private field within the UserControl, and as three public methods to the control: Add, Clear, and Remove

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900