//输出的时候
MouseEventArgs mouseArgs为{X=189 Y=168}
//我定义了一个
string str="X=189 Y=168"
用什么办法把str转换成MouseEventArgs或者EventArgs类型?本人菜鸟,求高手解决。

解决方案 »

  1.   

     [Serializable]
        public enum MacroEventType
        {
            MouseMove,
            MouseDown,
            MouseUp,
            MouseWheel,
            KeyDown,
            KeyUp,
            KeyPress
        }    /// <summary>
        /// Series of events that can be recorded any played back
        /// </summary>
        [Serializable]
        public class MacroEvent
        {        public MacroEventType MacroEventType;
            public EventArgs EventArgs;
            public int TimeSinceLastEvent;        public MacroEvent(MacroEventType macroEventType, EventArgs eventArgs, int timeSinceLastEvent)
            {            MacroEventType = macroEventType;
                EventArgs = eventArgs;
                TimeSinceLastEvent = timeSinceLastEvent;        }
        }
    void mouseHook_MouseMove(object sender, MouseEventArgs e)
            {            events.Add(
                    new MacroEvent(
                        MacroEventType.MouseMove,
                        e,
                        Environment.TickCount - lastTimeRecorded
                    ));            lastTimeRecorded = Environment.TickCount;        } case MacroEventType.MouseMove:
                                {                                MouseEventArgs mouseArgs = (MouseEventArgs)macroEvent.EventArgs;                                MouseSimulator.X = mouseArgs.X;
                                    MouseSimulator.Y = mouseArgs.Y;                            }
                                break;
      

  2.   

    你给出的代码中哪一行需要将string转换为MouseEventArgs?“VS设了断点以后显示出来的”跟你的题目又是有怎样关系的?看不明白你的描述。
      

  3.   

    呵呵,高人不明白菜鸟的想啊那说简单一点,就是如何把string转换成EventArgs的类型。
      

  4.   

    唉。乱写一个吧。private static  YourClass Converter(string str)
    {
        var xy = str.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        var ret = new YourClass();
        foreach (var x in xy)
        {
            var ex = x.Split(new char[] { '=' }, 2);
            if (ex[0].Trim().ToUpper() == "X")
                ret.x = int.Parse(ex[1]);
            else if (ex[0].Trim().ToUpper() == "Y")
                ret.y = int.Parse(ex[1]);
        }
        return ret;
    }
      

  5.   

    ret.x  改为  ret.X
    ret.y  改为  ret.Y
      

  6.   


    说高级一点就是给你一个鼠标x,y位置如何转换成MouseEventArgs e
      

  7.   

    MouseMove,X=630 Y=325
    MouseMove,X=631 Y=326
    像这样我把鼠标的动作输出到了文本文件,现在我想还原成鼠标事件,不知道这样说明白了没有?
      

  8.   


                string str = "X=189 Y=168";
                Match match = System.Text.RegularExpressions.Regex.Match(str, "X=([0-9]+) Y=([0-9]+)");
                int x = int.Parse(match.Groups[1].Value);
                int y = int.Parse(match.Groups[2].Value);
                MouseEventArgs e = new MouseEventArgs(MouseButtons.Left, 1, x, y, 0);
      

  9.   


    说高级一点就是给你一个鼠标x,y位置如何转换成MouseEventArgs e又变成“给你一个鼠标x,y位置”了?不是string了?代码都有了,就看你能不能自己读懂了。