牢骚-关于12530彩铃
今天开通了彩铃..进入wh.12530.com设置彩铃..
找了老半天.硬是没有找到免费彩铃区域…
没有办法.请教了专业人士.才勉强找到了少之又少,可怜的几首免费彩铃.
对于我这个自认为还是会用电脑的人来讲.找个免费的彩铃都这么难.可想而知了…移动真是黑…..
ListView VirtualMode
namespace ListviewVirtualTest
{
partial class Form2
{
/**//// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/**//// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name=”disposing”>如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
Windows 窗体设计器生成的代码#region Windows 窗体设计器生成的代码
/**//// <summary>
/// 设计器支持所需的方法 – 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(1, 2);
this.button1.Name = “button1″;
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = “button1″;
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// listView1
//
this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2});
this.listView1.Location = new System.Drawing.Point(1, 31);
this.listView1.Name = “listView1″;
this.listView1.Size = new System.Drawing.Size(592, 388);
this.listView1.TabIndex = 1;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.listView1_ColumnClick);
//
// columnHeader1
//
this.columnHeader1.Width = 138;
//
// columnHeader2
//
this.columnHeader2.Width = 214;
//
// button2
//
this.button2.Location = new System.Drawing.Point(82, 2);
this.button2.Name = “button2″;
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = “button2″;
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(163, 2);
this.button3.Name = “button3″;
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 3;
this.button3.Text = “button3″;
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(595, 431);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.listView1);
this.Controls.Add(this.button1);
this.Name = “Form2″;
this.Text = “Form2″;
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ListviewVirtualTest
{
public partial class Form2 : Form
{
private List<ListViewItem> m_hListViewItems;
private MySorter mySorter;
public Form2()
{
InitializeComponent();
m_hListViewItems = new List<ListViewItem>();
mySorter = new MySorter();
}
void listView_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
{
e.Item = m_hListViewItems[e.ItemIndex];
}
private void button1_Click(object sender, EventArgs e)
{
int NR = 10000;
for (int i = 0; i < NR; i++)
m_hListViewItems.Add(
new ListViewItem(new string[] { i + ” test1″, i + ” test2″ }));
listView1.RetrieveVirtualItem += new RetrieveVirtualItemEventHandler(listView_RetrieveVirtualItem);
listView1.VirtualListSize = NR;
listView1.VirtualMode = true;
}
//更新
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < m_hListViewItems.Count; i++)
{
m_hListViewItems[i].SubItems[0].Text = i + ” ” + DateTime.Now.ToString();
m_hListViewItems[i].SubItems[1].Text = i + ” ” + DateTime.Now.ToString();
}
listView1.Invalidate();
}
// 删除
private void button3_Click(object sender, EventArgs e)
{
List<ListViewItem> list = new List<ListViewItem>();
for (int i = 0; i < m_hListViewItems.Count; i += 2)
{
list.Add(m_hListViewItems[i]);
}
foreach (ListViewItem lvi in list)
{
m_hListViewItems.Remove(lvi);
}
listView1.VirtualListSize = m_hListViewItems.Count;
listView1.Invalidate();
}
//排序
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (e.Column == mySorter.ColumnIndex)
{
mySorter.SortOrder = (
mySorter.SortOrder == SortOrder.Descending ?
SortOrder.Ascending : SortOrder.Descending);
}
else
{
mySorter.SortOrder = SortOrder.Ascending;
mySorter.ColumnIndex = e.Column;
}
m_hListViewItems.Sort(mySorter);
listView1.Invalidate();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace ListviewVirtualTest
{
public class MySorter : System.Collections.Generic.IComparer<ListViewItem>
{
public SortOrder SortOrder = SortOrder.None;
public int ColumnIndex = -1;
IComparer 成员#region IComparer<ListViewItem> 成员
public int Compare(ListViewItem x, ListViewItem y)
{
ListViewItem hLeft = x;
ListViewItem hRiht = y;
if (SortOrder == SortOrder.Ascending && (ColumnIndex >= 0) && (ColumnIndex < hLeft.SubItems.Count))
{
string sx = hLeft.SubItems[ColumnIndex].Text;
string sy = hRiht.SubItems[ColumnIndex].Text;
return sx.CompareTo(sy);
}
if (SortOrder == SortOrder.Descending && (ColumnIndex >= 0) && (ColumnIndex < hLeft.SubItems.Count))
{
string sx = hLeft.SubItems[ColumnIndex].Text;
string sy = hRiht.SubItems[ColumnIndex].Text;
return sy.CompareTo(sx);
}
return 0;
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace ListviewVirtualTest
{
static class Program
{
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form2());
}
}
}
[转]VS2005 C#多线程中调用窗体控件的解决方案
以前在使用VS2003时,不会因为在线程里面对其它线程中的控件进行操作而报错,可到了VS2005这样操作就变成一个异常了,据说这是为了线程之间的安全性。
没办法了,只能找新的方法来实现原来的跨线程操作了!
(在讲解如何进行跨线程操作前,我抄一段摘自网上关于VS2005进行这一改动好处的说法:
由于Windows窗体控件本质上不是线程安全的。因此如果有两个或多个线程适度操作某一控件的状态(set value),则可能会迫使该控件进入一种不一致的状态。还可能出现其他与线程相关的bug,包括争用和死锁的情况。因此VS2005这一改动可以增强线程安全性。)
我想大家更关心的是如何解决这个问题,如何才能操作其它线程中的控件而不引发异常,接下来我们就来探讨下这个问题:
第一种方法:
这种方法我没用过,因为大家推荐不要使用,所以我没去实验过,具体方法如下(摘自网上):
设置System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;(winform.下)如果在你的程序初始化的时候设置了这个属性,而且在你的控件中使用的都是微软Framework类库中的控件的话,系统就不会再抛出你上面所说的这个错误了。当然这只是为了将VS2003的代码转换到VS2005下所使用的一种常见的方法。不建议采用。
第二种方法:
也是我今天主要要讲的就是利用delegate和invoke这2个方法:
思路:把想对另一线程中的控件实施的操作放到一个函数中,然后使用delegate代理那个函数,并且在那个函数中加入一个判断,用InvokeRequired来判断调用这个函数的线程是否和控件线程在同一线程中,如果是则直接执行对控件的操作,否则(不在同一线程中)利用控件的Invoke或BeginInvoke方法来执行这个代理。
在继续讲解下去之前我们先来看一下这里提到的几个方法(如果对以下两个东东已经了解了就可以跳过)
首先是Invoke,Invoke的中文解释是唤醒,它有两种参数类型我们这里只讲一种即(Delegate, Object[]),Delegate就是前面提到的那个代理,而Object[]则是用来存放Delegate所代理函数的参数。
MSDN上关于Invoke方法有如下说明:在拥有控件的基础窗口句柄的线程上,用指定的参数列表执行指定委托。用通俗的话讲就是利用控件的Invoke方法,使该控件所在的线程执行这个代理,也就是执行我们想对控件进行的操作,相当于唤醒了这个操作;
其次是控件的InvokeRequired,这个属性(个人翻译为’唤醒请求’):
MSDN上关于它的解释是获取一个值,该值指示调用方在对控件进行方法调用时是否必须调用Invoke方法,因为调用方位于创建控件所在的线程以外的线程中。用通俗的话讲就是返回一个值,如果与控件属于同一个线程,则不需要进行唤醒的请求,也就是返回值为False,否则则需要进行唤醒的请求,返回为true。
总感觉MSDN上的翻译让人无法一看就明白,可能是自己智力不够吧~~
————————————————————————————————————————–
最后就是我们的具体程序了:
delegate void aa(string s);//创建一个代理
//这个就是我们的函数,我们把要对控件进行的操作放在这里
private void pri(string t)
{
//判断是否需要进行唤醒的请求
//如果控件与主线程在一个线程内可以写成if(!InvokeRequired)
if(!richTextBox1.InvokeRequired)
{
MessageBox.Show("同一线程内");
richTextBox1.Text =t;
}
else
{
MessageBox.Show("不是同一个线程");
aa a1 =new aa(pri);
Invoke(a1,new object []{t});//执行唤醒操作
}
}
private void Form1_Load(object sender, System.EventArgse)
{
Thread newthread = new Thread(new ThreadStart(ttread));
newthread.Start();
}
void ttread()
{
pri("sdfs");
}
执行结果先调出一个提示框显示“不是同一个线程”,然后跳出提示框显示“同一线程内”,然后richTextBox1中的text值为sdfs;这样便完成了对其它线程中的控件进行操作。
湖北移动代理商接入地址
湖北移动代理商接入地址
VPN登录地址:https://211.137.74.41
网站接入地址(如果遇到那个地址进入不了,就换另外的地址进入):
http://wh.boss.hb.cmcc:8080/ngcrm/bsf/index.action
http://10.25.5.170:8080/ngcrm/bsf/index.action
http://10.25.5.1718080/ngcrm/bsf/index.action

SKIN#专业换肤
事事问
滴答表格