線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:5488
推到 Plurk!
推到 Facebook!

VS2003 C# - 模擬 iPhone 從左右滑出的滑動菜單效果

 
digitraveler
初階會員


發表:89
回覆:91
積分:46
註冊:2005-06-01

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-09-11 15:18:09 IP:59.127.xxx.xxx 訂閱
最近要把 POS 程式改成無鍵盤的觸控螢幕操作 , 所以所有的功能鍵都要做在螢幕上 , 但在商品銷售時要藏起來 , 無意間看見朋友的 iPhone 的滑動菜單效果 , 想說何不來模擬這種效果 , 當收銀員需要選單時 , 只要把手指在 this.panel1.Controls.Add(this.pictureBox1);
this.panel1.Location = new System.Drawing.Point(306, 1);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(336, 495);
this.panel1.TabIndex = 3;
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(8, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(320, 480);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// timer2
//
this.timer2.Enabled = true;
this.timer2.Interval = 10;
this.timer2.Tick = new System.EventHandler(this.timer2_Tick);
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 224);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(320, 272);
this.dataGrid1.TabIndex = 4;
//
// listBox1
//
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(144, 88);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(136, 112);
this.listBox1.TabIndex = 5;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(337, 493);
this.Controls.Add(this.panel1);
this.Controls.Add(this.button1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.listBox1);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.Load = new System.EventHandler(this.Form1_Load);
this.Closed = new System.EventHandler(this.Form1_Closed);
this.Activated = new System.EventHandler(this.Form1_Activated);
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
//Application.Run(new Form1());

_hookID = SetHook(_proc);
Application.Run(new Form1());
UnhookWindowsHookEx(_hookID);

}

//---------------------------------------------------------------------------
private static IntPtr SetHook(LowLevelMouseProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_MOUSE_LL, proc,
GetModuleHandle(curModule.ModuleName), 0);
}
}

//---------------------------------------------------------------------------
private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);

private static IntPtr HookCallback(
int nCode, IntPtr wParam, IntPtr lParam)
{

MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
xPos=hookStruct.pt.x;
yPos=hookStruct.pt.y;


if (nCode >= 0)
{
switch ((MouseMessages)wParam.ToInt32())
{
case MouseMessages.WM_LBUTTONDOWN :

press_flag=true;
PrevX=xPos;
PrevY=yPos;
break;

case MouseMessages.WM_LBUTTONUP :

press_flag=false;
turn_left=false;
turn_right=false;
turn_up=false;
turn_down=false;
break;

case MouseMessages.WM_MOUSEMOVE :

if (press_flag)
{
//Left = Left (X-PrevX);
//Top = Top (Y-PrevY);

turn_left=(xPos turn_right=(xPos>PrevX);
turn_up=(yPos turn_down=(yPos>PrevY);

}
PrevX=xPos;
PrevY=yPos;

break;

}
}

return CallNextHookEx(_hookID, nCode, wParam, lParam);
}

//---------------------------------------------------------------------------
private void Form1_Load(object sender, System.EventArgs e)
{
//
}

//---------------------------------------------------------------------------
private void Form1_Activated(object sender, System.EventArgs e)
{
panel1.Left=this.Width;


press_flag=false;
turn_left=false;
turn_right=false;
turn_up=false;
turn_down=false;
move_left=false;
move_right=false;

}

//---------------------------------------------------------------------------
private void Form1_Closed(object sender, System.EventArgs e)
{

}

//---------------------------------------------------------------------------
private void timer1_Tick(object sender, System.EventArgs e)
{
this.Text="";
if (turn_left)
{
this.Text=this.Text "turn_left ";

move_left=true;
move_right=false; //預防兩造同時 true
}
if (turn_right)
{
this.Text=this.Text "turn_right ";
move_right=true;
move_left=false; //預防兩造同時 true
}

if (turn_up) this.Text=this.Text "turn_up ";
if (turn_down) this.Text=this.Text "turn_down ";

turn_left=false;
turn_right=false;
turn_up=false;
turn_down=false;
}

//---------------------------------------------------------------------------
private void timer2_Tick(object sender, System.EventArgs e)
{
if (move_left)
{
//判斷位置區間
if (panel1.Left>=1)
{
panel1.Left=panel1.Left-20;
if (panel1.Left<1)
{
panel1.Left=0; //這裡有技巧
move_left=false;
}
}
else
{
panel1.Left=panel1.Left-20;
if (panel1.Left<(panel1.Width*-1))
{
panel1.Left=panel1.Width*-1;
move_left=false;
}
}

}
if (move_right)
{
//判斷位置區間
if (panel1.Left>=1)
{
panel1.Left=panel1.Left 20;
if (panel1.Left>this.Width)
{
panel1.Left=this.Width;
move_right=false;
}
}
else
{
panel1.Left=panel1.Left 20;
if (panel1.Left>1)
{
panel1.Left=1;
move_right=false;
}
}
}
}
//---------------------------------------------------------------------------
private void button1_Click(object sender, System.EventArgs e)
{
MessageBox.Show("你觸動了 CLICK 事件");
}



}
}


[/code]


■ 詳細內容請見

http://tw.myblog.yahoo.com/bruce0211/article?mid=234&prev=93&next=225


編輯記錄
digitraveler 重新編輯於 2009-09-11 15:20:50, 註解 無‧
digitraveler 重新編輯於 2009-09-11 15:21:49, 註解 無‧
digitraveler 重新編輯於 2009-09-11 15:22:38, 註解 無‧
careychen
尊榮會員


發表:41
回覆:580
積分:959
註冊:2004-03-03

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-09-11 22:16:32 IP:59.126.xxx.xxx 訂閱
讚哦,感謝分享~~!
------
價值的展現,來自於你用哪一個角度來看待它!!
系統時間:2024-11-21 20:40:06
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!