C#写的类似手机滑屏源代码(欢迎转载)
来源:互联网 发布:js touchend 触发多次 编辑:程序博客网 时间:2024/06/02 00:30
基类MListItem---------------------------------------------------------------
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 MoveableListLib
{
public partial class MListItem : UserControl
{
private Point startLocation;
private Point endLocation;
private Point initLocation;
private int id = -1;
private int dy = 0;
public MListItem(string index)
{
InitializeComponent();
this.lblContent.Text += index;
id = int.Parse(index);
initLocation = this.Location;
}
private void label1_Click(object sender, EventArgs e)
{
MessageBox.Show(this.lblContent.Text +"的详细信息!");
}
private void MListItem_MouseDown(object sender, MouseEventArgs e)
{
MoveableList.firstCtrlLocation = this.Parent.Controls[0].Location;
if (e.Button == MouseButtons.Left)
{
int size = this.Parent.Controls.Count;
startLocation = e.Location;
}
}
private void MListItem_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (startLocation != null)
{
endLocation = e.Location;
int xx = endLocation.Y - startLocation.Y;
if (Math.Abs(xx)>0.1)
reloadCtrlPosition(xx);
}
}
}
private void MListItem_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (startLocation != null)
{
dy = this.Location.Y - initLocation.Y;
if (dy == 0)
return;
SetPosition();
}
}
}
/// <summary>
/// 重新计算位置
/// </summary>
/// <param name="xx">变化值</param>
private void reloadCtrlPosition(int xx)
{
foreach (Control ctrl in this.Parent.Controls)
{
ctrl.Location = new Point(0, ctrl.Location.Y + xx);
}
}
private void SetPosition()
{
if (dy > 0)
{
if (-MoveableList.firstCtrlLocation.Y == 0)
{
do
{
foreach (Control ctrl in this.Parent.Controls)
{
ctrl.Location = new Point(0, ctrl.Location.Y - 1);
}
}
while (--dy != 0);
}
else
{
if(dy>=100)
{
dy = this.Height - dy;
do
{
foreach (Control ctrl in this.Parent.Controls)
{
ctrl.Location = new Point(0, ctrl.Location.Y + 1);
}
}
while (--dy != 0);
}
else
{
do
{
foreach (Control ctrl in this.Parent.Controls)
{
ctrl.Location = new Point(0, ctrl.Location.Y - 1);
}
}
while (--dy != 0);
}
MoveableList.firstCtrlLocation.Y = this.Parent.Controls[0].Location.Y;
}
}
else
{
dy = -dy;
if (-MoveableList.firstCtrlLocation.Y == this.Height * (this.Parent.Controls.Count - 1))
{
do
{
foreach (Control ctrl in this.Parent.Controls)
{
ctrl.Location = new Point(0, ctrl.Location.Y + 1);
}
}
while (--dy != 0);
}
if (-MoveableList.firstCtrlLocation.Y < this.Height * (this.Parent.Controls.Count - 1))
{
if (dy >= 100)
{
dy = this.Height - dy;
do
{
foreach (Control ctrl in this.Parent.Controls)
{
ctrl.Location = new Point(0, ctrl.Location.Y - 1);
}
}
while (--dy != 0) ;
}
else
{
do
{
foreach (Control ctrl in this.Parent.Controls)
{
ctrl.Location = new Point(0, ctrl.Location.Y + 1);
}
}
while (--dy != 0);
}
MoveableList.firstCtrlLocation.Y = this.Parent.Controls[0].Location.Y;
}
}
}
}
}
基类MoveableList----------------------------------------------------------
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;
using System.Collections;
namespace MoveableListLib
{
public partial class MoveableList : UserControl
{
//存储菜单项
public ArrayList arrList = new ArrayList();
//最大数目
private int max =5;
//单元数目
private int unit = 5;
public static Point firstCtrlLocation;
public MoveableList()
{
InitializeComponent();
//初始化
initListContent();
}
public MoveableList(int pMax,int pUnit):this()
{
max = pMax;
unit = pUnit;
}
/// <summary>
/// 设置大小
/// </summary>
/// <param name="pMax">最大记录数</param>
/// <param name="pUnit">加载单位记录数</param>
public void setItemsSize(int pMax, int pUnit)
{
max = pMax;
unit = pUnit;
}
/// <summary>
/// 初始化内容
/// </summary>
public void initListContent()
{
for (int i = 0; i < unit; i++)
{
MListItem item = new MListItem(i.ToString());
item.Location = new Point(0,item.Height * i);
this.Controls.Add(item);
}
}
/// <summary>
/// 加载新数据
/// </summary>
/// <param name="lastPosition">最后一条记录的位置</param>
public void loadNewData(int lastPosition)
{
int currentSize =this.Controls.Count;
for (int i = 0; i < unit; i++)
{
MListItem item = new MListItem((currentSize+i).ToString());
item.Location = new Point(0, item.Height *i + lastPosition);
this.Controls.Add(item);
}
}
/// <summary>
/// 是否还存在其他数据
/// </summary>
/// <returns></returns>
public bool existOtherData()
{
if (this.Controls.Count < max)
return true;
return false;
}
}
}
- C#写的类似手机滑屏源代码(欢迎转载)
- htm2txt c#源代码(转载)
- Delphi 写的欢迎界面 类似 WinRAR 按钮
- C#写的email 初级系统源代码
- 公布C#写的网游外挂源代码
- C#写的OPC客户端示例源代码
- C#写的邮箱发送程序源代码
- 【转载】用C#语言实现类似QQ的截图功能
- C#自写的一个HTML解析类(类似XElement语法)
- 本人写的手机狗(防盗软件)欢迎下载
- 【转载】C#写的字符串截取函数
- jQuery自己写的一个类似google自动提示的插件,源代码奉上
- 公布之前关于C#写的SNIFFER的全部源代码
- C#自己写的文本文件日志的实现源代码
- 发表一个自己C#写的email 初级系统源代码
- 发布C#语言写的智能客户端程序源代码
- UDP协议+C#写的一款局域网聊天工具+源代码
- C#写的一款音乐播放器+源代码下载
- 要好好总结一下超大矩阵求逆的技巧了
- 【Hash】Sacrament of Sum
- C/C++源代码到可执行程序的过程详解
- Fluent syntax 与Query Expression syntax在LINQ中的应用
- 黑马程序员——贪吃蛇游戏项目分析过程
- C#写的类似手机滑屏源代码(欢迎转载)
- Boost在linux中编译
- python学习之二——控制语句
- XmlDocument中的空格换行节点去除问题。
- Uboot_移植_记录_/*嵌入式学习*/
- 深入分析MFC 文档视图结构一
- <setjmp.h>非局部跳转(来自C语言程序设计--现代方法第二版)
- VC++ 6.0下对配置设置文件的存取访问
- ABAP/4中参数的传递