Форум программистов, компьютерный форум, киберфорум
C# Windows Forms
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 5.00/5: Рейтинг темы: голосов - 5, средняя оценка - 5.00
0 / 0 / 0
Регистрация: 11.06.2016
Сообщений: 2
1

Что такое Mybutton и почему не работает код "пятнашки"?

18.06.2016, 16:59. Показов 966. Ответов 3
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace WindowsFormsApplication7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Mybutton[] Butons = new Button[16];
 
        private void Form1_Load(object sender, EventArgs e)
        {
            int i = 0;
            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    Butons[i] = new Button();
                    Butons[i].Size = new Size(50, 50);
                    //Butons[i].Click += new EventHandler(Buttons_Click);
                    Butons[i].Location = new Point(12 + x * 56, 41 + y * 56);
                  //  Butons[i].Pozition = new Point(x, y);
                    this.Controls.Add(Butons[i]);
                    Butons[i].Text = ((i++) + 1).ToString();
                }
            }
            Butons[15].Visible = false;
        }
        private void Buttons_Click(object sender, EventArgs e)
        {
            MyButton Now = (MyButton)sender;
            int x = Math.Abs(Now.Pozition.X - Butons[15].Pozition.X);
            int y = Math.Abs(Now.Pozition.Y - Butons[15].Pozition.Y);
            if ((x == 1 && y == 0) || (x == 0 && y == 1))
            {
                Point P = Now.Pozition;
                Now.Pozition = Butons[15].Pozition;
                Butons[15].Pozition = P;
                Now.Location = new Point(12 + Now.Pozition.X * 56, 41 + Now.Pozition.Y * 56);
                Butons[15].Location = new Point(12 + Butons[15].Pozition.X * 56, 41 + Butons[15].Pozition.Y * 56);
                if (victory()) MessageBox.Show("Вы победили!");
            }
        }
        private bool victory()
        {
            int i = 0;
            for (int y = 0; y < 4; y++)
                for (int x = 0; x < 4; x++)
                    if (Butons[i++].Location != new Point(12 + x * 56, 41 + y * 56)) return false;
            return true;
        }
 
 
 
        private void button1_Click(object sender, EventArgs e)
       {
        List<int> list = new List<int>();
       for (int i = 0; i < 16; i++) list.Add(i);
       Random r = new Random();
        for (int y = 0; y < 4; y++)
         for (int x = 0; x < 4; x++)
        {
            int i = r.Next(0, list.Count);
            int number = list[i];
            list.RemoveAt(i);
            Butons[number].Location = new Point(12 + x * 56, 41 + y * 56);
            Butons[number].Pozition = new Point(x, y);
        }
}
    }
 
 
}
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
18.06.2016, 16:59
Ответы с готовыми решениями:

Почему этот код работает, кнопка реагирует на нажатия? И что такое as_p?
Почему это работает? Как вообще эта кнопка может что-то делать? {% extends 'blog/base.html' %}...

Что такое IIS и что такое PWS? Почему одно без другого не работает?
вот уже второй день пытаюсь немного разобраться в АСП. накидал небольшую тестовую страничку. но с...

Что такое «.\NUL»? И почему это не работает?
IF NOT EXIST %work%\NUL MKDIR %work%при запуске вот такой команды выходит диалоговое окно Эти...

Код не работает,говорит,что не знает,что такое delay(100).в чём проблема?как сделать,чтоб программа заработала?
#include &lt;graphics.h&gt; #include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; #include &lt;conio.h&gt; #include...

3
Администратор
Эксперт .NET
9602 / 4744 / 761
Регистрация: 17.04.2012
Сообщений: 9,592
Записей в блоге: 14
18.06.2016, 18:25 2
Код переписан как попало и не весь. Например, класс называется то Mybutton, то MyButton.
Судя по строке 19, это наследник класса Button, какой-то пользовательский компонент на основе кнопки, который в ваш код не попал.
0
98 / 101 / 30
Регистрация: 21.10.2012
Сообщений: 320
18.06.2016, 18:38 3
Перемешивание оставлено в качестве самостоятельного задания.

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        MyButton[] buttons = new MyButton[16];
 
        private void Form1_Load(object sender, EventArgs e)
        {
            int i = 0;
            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    buttons[i] = new MyButton();
                    buttons[i].Size = new Size(50, 50);
                    buttons[i].Click += new EventHandler(buttons_Click);
                    buttons[i].Location = new Point(12 + x * 56, 41 + y * 56);
                    buttons[i].Pozition = new Point(x, y);
                    this.Controls.Add(buttons[i]);
                    buttons[i].Text = ((i++) + 1).ToString();
                }
            }
            buttons[15].Visible = false;
        }
 
        private void buttons_Click(object sender, EventArgs e)
        {
            MyButton Now = (MyButton)sender;
            int x = Math.Abs(Now.Pozition.X - buttons[15].Pozition.X);
            int y = Math.Abs(Now.Pozition.Y - buttons[15].Pozition.Y);
            if ((x == 1 && y == 0) || (x == 0 && y == 1))
            {
                Point P = Now.Pozition;
                Now.Pozition = buttons[15].Pozition;
                buttons[15].Pozition = P;
                Now.Location = new Point(12 + Now.Pozition.X * 56, 41 + Now.Pozition.Y * 56);
                buttons[15].Location = new Point(12 + buttons[15].Pozition.X * 56, 41 + buttons[15].Pozition.Y * 56);
                if (Victory()) MessageBox.Show("Вы победили!");
            }
        }
 
        private bool Victory()
        {
            int i = 0;
            for (int y = 0; y < 4; y++)
                for (int x = 0; x < 4; x++)
                    if (buttons[i++].Location != new Point(12 + x * 56, 41 + y * 56)) return false;
            return true;
        }
    }
 
    public class MyButton : Button
    {
        public Point Pozition { get; set; }
    }
}
Добавлено через 7 минут
Кликните здесь для просмотра всего текста
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        MyButton[] buttons = new MyButton[16];
 
        private void Form1_Load(object sender, EventArgs e)
        {
            int i = 0;
 
            for (int y = 0; y < 4; ++y)
            {
                for (int x = 0; x < 4; ++x)
                {
                    buttons[i]          = new MyButton();
                    buttons[i].Size     = new Size(50, 50);
                    buttons[i].Click   += new EventHandler(buttons_Click);
                    buttons[i].Location = new Point(12 + x * 56, 41 + y * 56);
                    buttons[i].Position = new Point(x, y);
                    buttons[i].Text     = ((i++) + 1).ToString();
 
                    this.Controls.Add(buttons[i]);
                }
            }
            buttons[15].Visible = false;
        }
 
        private void buttons_Click(object sender, EventArgs e)
        {
            MyButton now = (MyButton)sender;
 
            int x = Math.Abs(now.Position.X - buttons[15].Position.X);
            int y = Math.Abs(now.Position.Y - buttons[15].Position.Y);
 
            if ((x == 1 && y == 0) || (x == 0 && y == 1))
            {
                Point point          = now.Position;
                now.Position         = buttons[15].Position;
                buttons[15].Position = point;
                now.Location         = new Point(12 + now.Position.X * 56, 41 + now.Position.Y * 56);
                buttons[15].Location = new Point(12 + buttons[15].Position.X * 56, 41 + buttons[15].Position.Y * 56);
 
                if (Victory())
                    MessageBox.Show("Вы победили!");
            }
        }
 
        private bool Victory()
        {
            int i = 0;
 
            for (int y = 0; y < 4; y++)
                for (int x = 0; x < 4; x++)
                    if (buttons[i++].Location != new Point(12 + x * 56, 41 + y * 56))
                        return false;
 
            return true;
        }
    }
 
    public class MyButton : Button
    {
        public Point Position { get; set; }
    }
}
0
979 / 874 / 350
Регистрация: 26.04.2012
Сообщений: 2,647
18.06.2016, 19:44 4
Нет смысла править данный код, так как он вырван из этой темы. Я там привел готовый работающий вариант-не знаю, что еще добавить.
0
18.06.2016, 19:44
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
18.06.2016, 19:44
Помогаю со студенческими работами здесь

Не могу понять почему не работает. Создаю игру Пятнашки. И ничего у меня не работает. И ошибки при запуске выдает
Не могу понять почему не работает. Создаю игру Пятнашки. И ничего у меня не работает. И ошибки при...

Почему не работает игра пятнашки
Я делаю игру пятнашки. Когда я просто использую html и js, я генерирую элементы динамически и...

Почему этот код не работает? Что не так с путем?
привет, у меня есть ошибка в коде ниже. Этот код преобразует все файлы txt в docx из той же папки....

Почему код не работает хотя ошибок нет? Что-то не так с выделением памяти?
#include &lt;math.h&gt; #include &lt;stdio.h&gt; #include &lt;conio.h&gt; #include &lt;iostream&gt; using namespace...

Не могу понять почему мой код работает не правильно.Прошу , подскажите что не так.Заранее спасибо)
#include &lt;iostream&gt; #include &lt;conio.h&gt; //#include &lt;stdio.h&gt; //#include &lt;stdfx.h&gt; using...

Почему массовое определение свойств объекта window работает, а для иных объектов такое не выходит, не работает?
можно записать: = ; и у объекта window появятся два новых определённых (имеющих значения)...

Почему именно такое определение работает?
Почему определение синуса, косинуса, тангенса, котангенса работает? Почему мы решили, что, если...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
4
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru