| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2187 人关注过本帖
标题:C#代码翻译..!
只看楼主 加入收藏
zhou363667565
Rank: 1
来 自:湖南株洲
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-10-26
收藏
 问题点数:0 回复次数:10 
C#代码翻译..!
这段代码对我很重要,我们就快交项目了.! 我想完成这个功能,!  请帮我解释一下, 别且写上注释,!   先谢谢各位了.1!

以下是一个右下角窗体 ,缓慢移动上升或下降的代码:

using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        int x = 0;  
        int y = 0;
        public Form1()
        {
            InitializeComponent();
            Form.CheckForIllegalCrossThreadCalls = false;
             x = Screen.PrimaryScreen.Bounds.Width - this.Width;
             y = Screen.PrimaryScreen.Bounds.Height;            
        }


        //窗体加载事件;
        private void Form1_Load(object sender, EventArgs e)
        {
            this.Location = new Point(x, y);
            timer1.Start();   //启用计时器;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            y = y - 10;
            this.Location = new Point(x, y);
            if (y <= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
            {
                timer1.Stop();
                System.Threading.Thread.Sleep(5000);
                this.Close();
            }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            while (true)
            {
                y = y + 10;
                this.Location = new Point(x, y);
                if (y >= Screen.PrimaryScreen.Bounds.Height)
                    break;
                System.Threading.Thread.Sleep(100);
            }
        }

    }
}
搜索更多相关主题的帖子: 注释 
2008-10-26 16:26
小仙
Rank: 7Rank: 7Rank: 7
来 自:光之谷
等 级:贵宾
威 望:39
帖 子:1812
专家分:1
注 册:2008-8-8
收藏
得分:0 
哎,都把这里当成了作业生成器了。


仁者乐膳,智者乐睡。我都爱~
2008-10-26 16:52
乖老鼠
Rank: 5Rank: 5
来 自:四川省
等 级:职业侠客
威 望:2
帖 子:434
专家分:394
注 册:2008-9-8
收藏
得分:0 
LZ,我都看懂了…你放到编译器里面会看不懂?

using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        int x = 0;
        int y = 0;
        public Form1()
        {
            InitializeComponent();
            //获取或设置一个值,该值指示是否捕获对错误线程的调用
            Form.CheckForIllegalCrossThreadCalls = false;
            //设置窗体左上角坐标X(主显示边界宽度减去当前窗体宽度)
            x = Screen.PrimaryScreen.Bounds.Width - this.Width;
            //设置窗体左上角坐标Y(主显示边界高度)
            y = Screen.PrimaryScreen.Bounds.Height;
        }


        //窗体加载事件;
        private void Form1_Load(object sender, EventArgs e)
        {
            //设置窗体相对于屏幕的位置(调用了前面的X,Y)
            this.Location = new Point(x, y);
            //启用计时器;
            timer1.Start();   
        }

        /// <summary>
        /// 计时器响应事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            y = y - 10;
            //窗体向上移动10个像素
            this.Location = new Point(x, y);
            //如果窗体已经全部显示,并且超出30个像素(为什么是30呢?),那么关闭窗体
            if (y <= Screen.PrimaryScreen.Bounds.Height - this.Height - 30)
            {
                //计时器不再需要,关闭掉
                timer1.Stop();
                //在关闭窗体前,让窗体静止显示5秒
                System.Threading.Thread.Sleep(5000);
                //关闭当前窗体
                this.Close();
            }
        }

        /// <summary>
        /// 窗体关闭前事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //while (true),无论如何,都会执行这个,直到break跳出
            while (true)
            {
                y = y + 10;
                //窗体下移10个像素
                this.Location = new Point(x, y);
                //如果窗体已经移出屏幕外,那么就可以跳出“关闭前事件”,执行FormClosed事件关闭窗体了
                if (y >= Screen.PrimaryScreen.Bounds.Height)
                    break;
                //这里为什么要延迟100毫秒呢?
                System.Threading.Thread.Sleep(100);
            }
        }

    }
}

[[it] 本帖最后由 乖老鼠 于 2008-10-27 09:45 编辑 [/it]]

转眼就从编程菜鸟混成了半灌水
2008-10-27 09:30
乖老鼠
Rank: 5Rank: 5
来 自:四川省
等 级:职业侠客
威 望:2
帖 子:434
专家分:394
注 册:2008-9-8
收藏
得分:0 
不晓得我理解得对不对

转眼就从编程菜鸟混成了半灌水
2008-10-27 09:49
ilovetea
Rank: 1
来 自:辽宁省锦州市
等 级:新手上路
帖 子:177
专家分:4
注 册:2008-3-31
收藏
得分:0 
支持乖老鼠


但我没看懂,更菜啊

[[it] 本帖最后由 ilovetea 于 2008-10-27 10:20 编辑 [/it]]

我是爱喝茶的胖子,有空一起喝茶啊
我的百度博客:http://hi.baidu.com/33806380
2008-10-27 10:18
seiya027848
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2008-6-27
收藏
得分:0 
多线程是比较麻烦的
2008-10-27 10:28
乖老鼠
Rank: 5Rank: 5
来 自:四川省
等 级:职业侠客
威 望:2
帖 子:434
专家分:394
注 册:2008-9-8
收藏
得分:0 
[bo][un]ilovetea[/un] 在 2008-10-27 10:18 的发言:[/bo]

支持乖老鼠


但我没看懂,更菜啊

我想撞墙

转眼就从编程菜鸟混成了半灌水
2008-10-27 11:52
zhong52111
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2008-9-1
收藏
得分:0 
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //while (true),无论如何,都会执行这个,直到break跳出
            while (true)
            {
                y = y + 10;
                //窗体下移10个像素
                this.Location = new Point(x, y);
                //如果窗体已经移出屏幕外,那么就可以跳出“关闭前事件”,执行FormClosed事件关闭窗体了
                if (y >= Screen.PrimaryScreen.Bounds.Height)
                    break;
                //这里为什么要延迟100毫秒呢?
                System.Threading.Thread.Sleep(100);
            }
当上面执行this。close();
那就触发事件每0.1 秒y+10最后就break;
2008-10-27 11:58
zhou363667565
Rank: 1
来 自:湖南株洲
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-10-26
收藏
得分:0 
o(∩_∩)o...。

谢谢大家,热心的回答.!    特别感谢米老鼠 . 注释,  写的很详细..!  同时,也感谢所有的回答着.!
2008-10-27 15:48
hkucbv
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-8-13
收藏
得分:0 
晕死,这个都不懂!!!!111
利用系统;使用System.Collections.Generic ;使用 ;使用System.Data ;使用System.Drawing ;使用System.Text ;使用System.Windows.Forms ;名字空间WindowsApplication1 (公共部分Form1类:表格(诠释x = 0 ;诠释为y = 0 ;公众在Form1 ( ) ( InitializeComponent ( ) ; Form.CheckForIllegalCrossThreadCalls =假; x = Screen.PrimaryScreen.Bounds 。宽度- this.Width ;为Y = Screen.PrimaryScreen.Bounds.Height ; ) / /窗体加载事件;私营无效Form1_Load (对象发送者, EventArgs五) ( this.Location =新的起点(的x , y ) ;定时器。启动( ) ; / /启用计时器; )私人无效timer1_Tick (对象发送者, EventArgs五) (为Y = Ÿ - 10 ; this.Location =新的起点(的x , y ) ;如果(是“ = Screen.PrimaryScreen.Bounds 。高度- this.Height - 30 ) ( timer1.St同( ) ; System.Threading.Thread.Sleep ( 5000 ) ; this.Close ( ) ; ) )私人无效Form1_FormClosing (对象发送者, FormClosingEventArgs五) (而(真正) (为Y = Ÿ + 10 ; this.Location =新点(的x , y ) ;如果(是“ = Screen.PrimaryScreen.Bounds.Height )破; System.Threading.Thread.Sleep ( 100 ) ; ) ) ) )
2009-08-13 16:57
快速回复:C#代码翻译..!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017374 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved