Модераторы: Partizan, gambit
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Графика 
:(
    Опции темы
ChiciucMaxim
Дата 14.9.2008, 13:38 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 34
Регистрация: 22.6.2008

Репутация: -1
Всего: нет



Добрый день. Подскажите пожалуйста, графы в С# рисуются с помощью GDI+?
PM MAIL   Вверх
kosmonaFFFt
Дата 14.9.2008, 16:40 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Опытный
**


Профиль
Группа: Участник
Сообщений: 538
Регистрация: 14.4.2008
Где: Иннополис

Репутация: нет
Всего: 5



Да хоть с помощью DirectX можно. Я делал так:
Код

//Перерисовка графа.
        public void Repaint()
        {
            PaintableGraph.GraphGraphics.Clear(Color.LightGray);
            for (Int32 Index = 0; Index < this.PaintableVertexList.Count; ++Index)
            {
                this.PaintableVertexList[Index].Paint(Index);
            }
            for (Int32 yIndex = 0; yIndex < this.Matrix.Count; ++yIndex)
            {
                for (Int32 xIndex = 0; xIndex < yIndex; ++xIndex)
                {
                    if (this.Matrix[yIndex][xIndex] != 0)
                    {
                        //X и Y вершины находятся примерно напротив друг друга относительно вертикали.
                        if (Math.Abs(this.PaintableVertexList[yIndex].GetX() - this.PaintableVertexList[xIndex].GetX()) < PaintableGraphVertex.GetSize())
                        {
                            //Вершина Y выше X.
                            if (this.PaintableVertexList[yIndex].GetY() + PaintableGraphVertex.GetSize() < this.PaintableVertexList[xIndex].GetY())
                            {
                                PaintableGraph.GraphGraphics.DrawLine(
                                 Pens.Black
                                 , this.PaintableVertexList[yIndex].GetX() + (PaintableGraphVertex.GetSize() / 2)
                                 , this.PaintableVertexList[yIndex].GetY() + PaintableGraphVertex.GetSize()
                                 , this.PaintableVertexList[xIndex].GetX() + (PaintableGraphVertex.GetSize() / 2)
                                 , this.PaintableVertexList[xIndex].GetY() 
                             );
                            }
                            //Вершина Y ниже вершины X.
                            else if (this.PaintableVertexList[yIndex].GetY() + PaintableGraphVertex.GetSize() > this.PaintableVertexList[xIndex].GetY())
                            {
                                PaintableGraph.GraphGraphics.DrawLine(
                                 Pens.Black
                                 , this.PaintableVertexList[yIndex].GetX() + (PaintableGraphVertex.GetSize() / 2)
                                 , this.PaintableVertexList[yIndex].GetY()
                                 , this.PaintableVertexList[xIndex].GetX() + (PaintableGraphVertex.GetSize() / 2)
                                 , this.PaintableVertexList[xIndex].GetY() + PaintableGraphVertex.GetSize()
                             );
                            }
                        }
                        //Y вершина левее X вершины.
                        else if (this.PaintableVertexList[yIndex].GetX() + PaintableGraphVertex.GetSize() < this.PaintableVertexList[xIndex].GetX())
                        {
                            //Высота примерно одинакова.
                            if (Math.Abs(this.PaintableVertexList[yIndex].GetY() - this.PaintableVertexList[xIndex].GetY()) < PaintableGraphVertex.GetSize())
                            {
                             PaintableGraph.GraphGraphics.DrawLine(
                                 Pens.Black
                                 , this.PaintableVertexList[yIndex].GetX() + PaintableGraphVertex.GetSize()
                                 , this.PaintableVertexList[yIndex].GetY() + (PaintableGraphVertex.GetSize() / 2)
                                 , this.PaintableVertexList[xIndex].GetX()
                                 , this.PaintableVertexList[xIndex].GetY() + (PaintableGraphVertex.GetSize() / 2)
                             );
                            }
                            //Вершина Y ниже вершины X.
                            else if (this.PaintableVertexList[yIndex].GetY() < this.PaintableVertexList[xIndex].GetY() + PaintableGraphVertex.GetSize())
                            {
                                PaintableGraph.GraphGraphics.DrawLine(
                                 Pens.Black
                                 , this.PaintableVertexList[yIndex].GetX() + PaintableGraphVertex.GetSize()
                                 , this.PaintableVertexList[yIndex].GetY() + PaintableGraphVertex.GetSize()
                                 , this.PaintableVertexList[xIndex].GetX()
                                 , this.PaintableVertexList[xIndex].GetY() 
                             );
                            }
                            //Вершина Y выше вершины X.
                            else if (this.PaintableVertexList[yIndex].GetY() > this.PaintableVertexList[xIndex].GetY() + PaintableGraphVertex.GetSize())
                            {
                                PaintableGraph.GraphGraphics.DrawLine(
                                 Pens.Black
                                 , this.PaintableVertexList[yIndex].GetX() + PaintableGraphVertex.GetSize()
                                 , this.PaintableVertexList[yIndex].GetY() 
                                 , this.PaintableVertexList[xIndex].GetX()
                                 , this.PaintableVertexList[xIndex].GetY() + PaintableGraphVertex.GetSize()
                             );
                            }
                        }
                        //Y веошина лежит правее X вершины.
                        else if (this.PaintableVertexList[yIndex].GetX() + PaintableGraphVertex.GetSize() > this.PaintableVertexList[xIndex].GetX())
                        {
                            //Высота примерно одинакова.
                            if (Math.Abs(this.PaintableVertexList[yIndex].GetY() - this.PaintableVertexList[xIndex].GetY()) < PaintableGraphVertex.GetSize())
                            {
                             PaintableGraph.GraphGraphics.DrawLine(
                                 Pens.Black
                                 , this.PaintableVertexList[yIndex].GetX()
                                 , this.PaintableVertexList[yIndex].GetY() + (PaintableGraphVertex.GetSize() / 2)
                                 , this.PaintableVertexList[xIndex].GetX() + PaintableGraphVertex.GetSize()
                                 , this.PaintableVertexList[xIndex].GetY() + (PaintableGraphVertex.GetSize() / 2)
                             );
                            }
                            //Вершина Y ниже вершины X.
                            else if (this.PaintableVertexList[yIndex].GetY() < this.PaintableVertexList[xIndex].GetY() + PaintableGraphVertex.GetSize())
                            {
                                PaintableGraph.GraphGraphics.DrawLine(
                                 Pens.Black
                                 , this.PaintableVertexList[yIndex].GetX() 
                                 , this.PaintableVertexList[yIndex].GetY() + PaintableGraphVertex.GetSize()
                                 , this.PaintableVertexList[xIndex].GetX() + PaintableGraphVertex.GetSize()
                                 , this.PaintableVertexList[xIndex].GetY() 
                             );
                            }
                            //Вершина Y выше вершины X.
                            else if (this.PaintableVertexList[yIndex].GetY() > this.PaintableVertexList[xIndex].GetY() + PaintableGraphVertex.GetSize())
                            {
                                PaintableGraph.GraphGraphics.DrawLine(
                                 Pens.Black
                                 , this.PaintableVertexList[yIndex].GetX() 
                                 , this.PaintableVertexList[yIndex].GetY() 
                                 , this.PaintableVertexList[xIndex].GetX() + PaintableGraphVertex.GetSize()
                                 , this.PaintableVertexList[xIndex].GetY() + PaintableGraphVertex.GetSize()
                             );
                            }
                        }
                        //Прорисовка веса.
                        PaintableGraph.GraphGraphics.DrawString(
                            this.Matrix[yIndex][xIndex].ToString()
                            , new Font("verdana", 9)
                            , Brushes.Black
                            , (this.PaintableVertexList[yIndex].GetX() + PaintableGraphVertex.GetSize() + this.PaintableVertexList[xIndex].GetX()) / 2
                            , (this.PaintableVertexList[yIndex].GetY() + PaintableGraphVertex.GetSize() + this.PaintableVertexList[xIndex].GetY()) / 2 - 18
                        );
                    }
                }
            }
        }


и так

Код

//Отрисовка вершины.
        public void Paint(Int32 NumberVal)
        {
            //Т. к. вершина не знает своего номера - номер принимается в качестве параметра.
            PaintableGraphVertex.VertexGraphics.DrawRectangle(
                Pens.Black
                , this.X
                , this.Y
                , PaintableGraphVertex.VertexSize
                , PaintableGraphVertex.VertexSize);
            PaintableGraphVertex.VertexGraphics.DrawString(NumberVal.ToString()
                                                           , new Font("Verdana", 9)
                                                           , Brushes.Black
                                                           , this.X + (PaintableGraphVertex.VertexSize / 2 - 6)
                                                           , this.Y + (PaintableGraphVertex.VertexSize / 2 - 8));
        }



--------------------
user posted image
PM MAIL ICQ   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Прежде чем создать тему, посмотрите сюда:
mr.DUDA
THandle

Используйте теги [code=csharp][/code] для подсветки кода. Используйтe чекбокс "транслит" если у Вас нет русских шрифтов.
Что делать если Вам помогли, но отблагодарить помощника плюсом в репутацию Вы не можете(не хватает сообщений)? Пишите сюда, или отправляйте репорт. Поставим :)
Так же не забывайте отмечать свой вопрос решенным, если он таковым является :)


Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, mr.DUDA, THandle.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Общие вопросы по .NET и C# | Следующая тема »


 




[ Время генерации скрипта: 0.0437 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.