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

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> Сплывающие окна, Как сделано в Visual Studio 
:(
    Опции темы
kma
Дата 29.11.2007, 12:04 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


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

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



Мне не обходимо реализовать сплывающие окна как это сделано в Visual Studio меню Properties, не давно перешел на Visual Studio 2005 поэтому не знаю с чего начать, подскажите плиз где можно посмотреть как это можно сделать или дайте пример. 
Заранее спасибо 
PM MAIL   Вверх
kma
Дата 30.11.2007, 17:22 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


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

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



Не ужели не кто с этим не когда не сталкивался или может я неправильно вопрос поставил? smile 
PM MAIL   Вверх
Dogo
Дата 2.12.2007, 19:55 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Шустрый
*


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

Репутация: 3
Всего: 9



К примеру, можно наследовать Panel...
MyControl.cs - движок
Код

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace MyControl
{
    public class MyRollingPanel : System.Windows.Forms.Panel
    {
        #region Enums
        public enum Conditions
        {
            RolledDown,
            RolledUp
        }
        #endregion

        #region Props'n'Fields
        private System.ComponentModel.Container components = null;

        private System.Windows.Forms.Timer RollingTimer;

        private int MouseX;
        private int MouseY;
        private int MouseXOnDown;
        private int MouseYOnDown;
        private bool Moveable = false;

        private Color pri_HeaderBackground;
        [Category("Appearance"), Description("Цвет шапки")]
        public  Color HeaderBackground
        {
            get
            {
                return this.pri_HeaderBackground;
            }
            set
            {
                this.pri_HeaderBackground = value;
                this.Refresh();
            }
        }

        private string pri_Caption;
        [Category("Appearance"), Description("Заголовок")]
        public  string Caption
        {
            get
            {
                return this.pri_Caption;
            }
            set
            {
                this.pri_Caption = value;
                this.Refresh();
            }
        }

        [DefaultValue(25)]
        private int pri_HeaderHight;
        [Category("Appearance"), Description("Высота шапки")]
        public  int HeaderHight
        {
            get
            {
                return this.pri_HeaderHight;
            }
            set
            {
                this.pri_HeaderHight = value;
                this.DockPadding.Top = value;
                this.Refresh();
            }
        }

        public Rectangle HeaderRect
        {
            get
            {
                return new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y,
                    this.ClientRectangle.Width, this.pri_HeaderHight);
            }
        }

        [DefaultValue(Conditions.RolledUp)]
        private Conditions pri_Condition;
        public  Conditions Condition
        {
            get
            {
                return this.pri_Condition;
            }
            set
            {
                this.pri_Condition = value;
                this.Refresh();
            }
        }

        private int pri__RolledUpHight;
        private  int pri_RolledUpHight
        {
            get
            {
                return this.pri__RolledUpHight;
            }
        }
        #endregion

        #region Constructor
        public MyRollingPanel()
        {
          InitializeComponent();            
        }
        #endregion

        #region Overriden Methods

        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        protected override void OnPaint(PaintEventArgs e)
        {    
            Painter.DrawRolligPanel(this, e.Graphics);
        }      

        protected override void OnMouseDown(MouseEventArgs e)
        {  
            if(e.Button == MouseButtons.Left)
                this.Moveable = true;

            this.MouseXOnDown = e.X;
            this.MouseYOnDown = e.Y;
            base.OnMouseDown (e);
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            this.MouseX = e.X;
            this.MouseY = e.Y;

            if(this.Moveable)
            {
                int Xstart, Ystart;
                int Xoffset, Yoffset;

                Xstart = this.Left;          
                Ystart = this.Top;
         
                Xoffset = e.X - this.MouseXOnDown;
                Yoffset = e.Y - this.MouseYOnDown;

                this.Left += Xoffset;
                this.Top  += Yoffset;          
            }

            base.OnMouseMove (e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            this.Moveable = false;
            base.OnMouseUp (e);
        }



        protected override void OnDoubleClick(EventArgs e)
        {      
            Rectangle FakeMouseRect = new Rectangle(this.MouseX, this.MouseY, 1, 1);
            if(FakeMouseRect.IntersectsWith(this.HeaderRect))
            {
                if(this.Condition == Conditions.RolledUp)
                {
                    this.RollMeDown();
                }
                else
                    this.RollMeUp();
            }
            base.OnDoubleClick (e);
        }

        #endregion

        #region Private Methods
        private void RollMeDown()
        {
            this.RollingTimer.Stop();
            this.pri__RolledUpHight = this.Height;
            this.Condition = Conditions.RolledDown;
            this.RollingTimer.Start();
        }

        private void RollMeUp()
        {
            this.Condition = Conditions.RolledUp;
            this.RollingTimer.Start();
        }

        private void RollingTimer_Tick(object sender, System.EventArgs e)
        {
            int D = 20;
            if(this.Condition == Conditions.RolledDown)
            {
                if(this.Height > this.HeaderHight)
                {
                    if(this.Height - D < this.HeaderHight)
                        this.Height = this.HeaderHight;
                    else
                        this.Height-=D;
                }
                else
                    this.RollingTimer.Stop();
            }
            else if(this.Condition == Conditions.RolledUp)
            {
                if(this.Height < this.pri__RolledUpHight)
                    this.Height+=D;
                else
                    this.RollingTimer.Stop();     
            }
            this.Refresh();
        }

        private void InitializeComponent()
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.DoubleBuffer, true);

            this.pri_HeaderHight = 15;
            this.DockPadding.Top = this.pri_HeaderHight;
            this.pri_Condition   = Conditions.RolledDown;
            this.pri__RolledUpHight = this.ClientRectangle.Height;

            components = new System.ComponentModel.Container();
            this.RollingTimer = new System.Windows.Forms.Timer(this.components);
            this.RollingTimer.Interval = 1;
            this.RollingTimer.Tick += new System.EventHandler(this.RollingTimer_Tick);
        }
      
        #endregion
    }
}


Painter.cs - класс занимающийся отрисовкой контрола
Код

using System;
using System.Drawing;

namespace MyControl
{
    public class Painter
    {
     #region Rolling Panel Methods

            public static void DrawRolligPanel(MyRollingPanel rlpnl, Graphics grfx)
            {
                Rectangle tmpRect    = new Rectangle(rlpnl.ClientRectangle.X, rlpnl.ClientRectangle.Y, rlpnl.ClientRectangle.Width-1, rlpnl.ClientRectangle.Height-1);

                grfx.FillRectangle(new SolidBrush(rlpnl.HeaderBackground), rlpnl.HeaderRect);  

                grfx.DrawRectangle(new Pen(new SolidBrush(Color.Black)), tmpRect);  

                Painter.DrawRollingPanelCaption(rlpnl, rlpnl.Caption, grfx);
            }

            private static void DrawRollingPanelCaption(MyRollingPanel rlpnl, string txt, Graphics grfx)
            {
                SizeF szfStr = grfx.MeasureString(txt, rlpnl.Font);

                int txtHeight = (int)szfStr.Height;

                int YOffset;

                StringFormat strfmt = new StringFormat();

                strfmt.Alignment = strfmt.LineAlignment = StringAlignment.Center;

                Rectangle HeaderRect = new Rectangle(rlpnl.ClientRectangle.Left, rlpnl.ClientRectangle.Top, rlpnl.ClientRectangle.Width, rlpnl.HeaderHight);

                YOffset = (HeaderRect.Height - txtHeight)/2;
    
                if(YOffset < 0)
                  YOffset = 0;         
 
                Rectangle txtShow = new Rectangle(HeaderRect.X, HeaderRect.Y + YOffset, rlpnl.ClientRectangle.Width, txtHeight);              

                grfx.DrawString("  "+txt, rlpnl.Font, new SolidBrush(rlpnl.ForeColor), txtShow, strfmt);
            }
        #endregion
    }
}




Это сообщение отредактировал(а) Dogo - 2.12.2007, 19:58
--------------------
 
PM MAIL ICQ   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Прежде чем создать тему, посмотрите сюда:
mr.DUDA
THandle

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


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

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | Разработка Windows Forms | Следующая тема »


 




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


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

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