选框标签与图像 [英] marquee label with images
问题描述
我有一个以我的形式移动的标签>>标签信息来自我的数据库中的表(新闻表)
标签中显示的新闻和移动但我想分开第一个新闻和第二个新闻一张图片
我该怎么办,,,,,就像电视频道的新闻栏一样
希望我能找到一些提示或帮助
i使用该代码从数据库移动和获取数据
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
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
if(l.Left> this.Width)
l.Left = 0;
其他
l.Left = l.Left + 1;
if (l.Left > this.Width)
l.Left = 0;
else
l.Left = l.Left + 1;
i不知道我可以在哪里调用我的图片作为分割器
是我最好的控制标签,还是我应该使用另一个控件
提前预付
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
推荐答案
你不能使用一个标签 - 或者至少没有很多的人选。
我会创建自己的UserControl,并在Paint事件中编写文本(并绘制图像) - 它并不复杂,并且它可能看起来比在标签文本上手动执行选框更好看,因为你可以选择速度像素而不是字符,因此它可以更平滑 - 记住大多数字体ar因此,i比W薄得多。如果你按字符选择,那么速度会根据你删除的字符而有所不同。
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.
感谢您的回答
它似乎是正确的一个
i将尝试创建我自己的用户控件的第一时间和我将回来告诉你它是否有效
thanx很多原始格里夫
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
我创建了控制器你说,但从表中带来的所有新闻都在图像之前
我用于控件的代码(用户控件包含标签和图片框)< br $> b $ b
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)
使用System;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Drawing;
使用System。数据;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;
命名空间WindowsFormsApplication8
{
public partial class news_uc:UserControl
{
public news_uc()
{
InitializeComponent();
}
public string news_text
{
get {return news.Text; }
set {news.Text = value;无效(); }
}
public Image img_news_delimetter
{
get {return img_delimetter.Image; }
set {img_delimetter.Image = value;无效(); }
}
公共字符串txt_news_delimetter
{
get {return text_delimiter.Text; }
set {text_delimiter.Text = value;无效(); }
}
}
}
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
使用System;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;
使用System.Data.SqlClient;
命名空间WindowsFormsApplication8
{
公共部分类Form1:表格
{
public SqlConnection fcon = new SqlConnection(@Data Source = ME- PC \ server; Initial Catalog = first_db; Integrated Security = True);
public SqlCommand cmd;
public SqlDataReader rdr;
< br $>
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 =新SqlCommand(select * from news where is_activated = 1 order by news_date,fcon);
if(fcon.State == ConnectionState。打开)
fcon.Close();
fcon.Open();
rdr = cmd.ExecuteReader();
while(rdr.Read())
{
news_uc1.news_text + = rdr [1] .ToString(); //
}
rdr.Close();
}
}
}
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问题在哪里>>>每次新闻后重复我的img
再次感谢
mmmmmmmmmmmm where is the problem >>> to repeat my img after each news
thanks again
这篇关于选框标签与图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!