Click here to Skip to main content
15,890,185 members
Home / Discussions / Windows Forms
   

Windows Forms

 
GeneralRe: Custom controll flickers! Pin
Luc Pattyn9-Jun-10 13:44
sitebuilderLuc Pattyn9-Jun-10 13:44 
GeneralRe: Custom controll flickers! Pin
venomation9-Jun-10 14:05
venomation9-Jun-10 14:05 
GeneralRe: Custom controll flickers! Pin
Luc Pattyn9-Jun-10 14:40
sitebuilderLuc Pattyn9-Jun-10 14:40 
GeneralRe: Custom controll flickers! Pin
venomation10-Jun-10 4:11
venomation10-Jun-10 4:11 
GeneralRe: Custom controll flickers! Pin
Luc Pattyn10-Jun-10 4:21
sitebuilderLuc Pattyn10-Jun-10 4:21 
GeneralRe: Custom controll flickers! Pin
venomation10-Jun-10 4:56
venomation10-Jun-10 4:56 
GeneralRe: Custom controll flickers! Pin
Luc Pattyn10-Jun-10 5:16
sitebuilderLuc Pattyn10-Jun-10 5:16 
GeneralRe: Custom controll flickers! Pin
venomation10-Jun-10 5:27
venomation10-Jun-10 5:27 
Well this is my latest code:

using System.Drawing;
using System.Windows.Forms;

namespace TileMapper.Presentation.Controls
{
    public partial class MapRenderer : UserControl
    {
        private Point _tileBound;
        private Point _rowsColumns;
        private bool _initalized = false;
        Rectangle[,] _renderBounds;
        public MapRenderer()
        {
            InitializeComponent();
            this.DoubleBuffered = true;

            // Activates double buffering 
            this.SetStyle(
               ControlStyles.OptimizedDoubleBuffer , true);
            this.UpdateStyles();
            panel1.HorizontalScroll.LargeChange = 1;


        }

        public void InitalizeGrid(int tileWidth, int tileHeight, int rows, int columns)
        {
            _tileBound = new Point(tileWidth, tileHeight);
            _rowsColumns = new Point(rows, columns);
            panel1.AutoScrollMinSize = new Size(_tileBound.X * _rowsColumns.X, _tileBound.Y * _rowsColumns.Y);
            _initalized = true;
            _pen = new Pen(Color.Black);
            _tile = new Rectangle(0, 0, _tileBound.X, _tileBound.Y);
            _im = Image.FromFile(@"C:/box.png");

            _scrollValue = new Point(panel1.HorizontalScroll.Value, panel1.VerticalScroll.Value);

            _renderBounds = new Rectangle[_tileBound.X, _tileBound.Y];

            for (int x = 0; x < _tileBound.X; x++)
            {
                for (int y = 0; y < _tileBound.Y; y++)
                {
                    _renderBounds[x,y] = new Rectangle(x * _tileBound.X
                       , y * _tileBound.Y, _tileBound.X, _tileBound.Y);
                }
            }
        }

        private Point _scrollValue;

        Pen _pen;
        Rectangle _tile;
        private Image _im;
        void DrawGrid(Graphics e, Rectangle bound)
        {
            int start = bound.X / _tileBound.X;
            int end = bound.X/_tileBound.X + bound.Width/_tileBound.X;

            int startY = bound.Y / _tileBound.Y;
            int endY = bound.Y + bound.Height/_tileBound.Y;

            for (int x = start; x < end; x++)
            {
                for (int y = startY; y < endY; y++)
                {
                   e.DrawImage(_im, _renderBounds[x,y], _tile, GraphicsUnit.Pixel);
                }

            }

        }





        private void panel1_Paint_1(object sender, PaintEventArgs e)
        {
            if (_initalized)
            {
                Rectangle a = e.ClipRectangle;

                _scrollValue.X = panel1.HorizontalScroll.Value;
                _scrollValue.Y = panel1.VerticalScroll.Value;

                DrawGrid(e.Graphics, a);
            }
        }

        private void panel1_Scroll(object sender, ScrollEventArgs e)
        {
          panel1.Invalidate();

        }

    }
}


..>Designer code..

namespace TileMapper.Presentation.Controls
{
    partial class MapRenderer
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.panel1 = new System.Windows.Forms.Panel();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.AutoScroll = true;
            this.panel1.BackColor = System.Drawing.Color.White;
            this.panel1.Location = new System.Drawing.Point(12, 24);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(583, 319);
            this.panel1.TabIndex = 0;
            this.panel1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.panel1_Scroll);
            this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint_1);
            // 
            // MapRenderer
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.panel1);
            this.Name = "MapRenderer";
            this.Size = new System.Drawing.Size(612, 358);
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Panel panel1;
    }
}

GeneralRe: Custom controll flickers! Pin
Luc Pattyn10-Jun-10 5:41
sitebuilderLuc Pattyn10-Jun-10 5:41 
GeneralRe: Custom controll flickers! Pin
venomation11-Jun-10 1:44
venomation11-Jun-10 1:44 
GeneralRe: Custom controll flickers! Pin
Luc Pattyn11-Jun-10 1:55
sitebuilderLuc Pattyn11-Jun-10 1:55 
QuestionDynamically data binding in tree view control in windows forms Pin
ims.sanjay1-Jun-10 9:11
ims.sanjay1-Jun-10 9:11 
AnswerRe: Dynamically data binding in tree view control in windows forms Pin
Peace ON1-Jun-10 21:47
Peace ON1-Jun-10 21:47 
AnswerRe: Dynamically data binding in tree view control in windows forms Pin
Mycroft Holmes1-Jun-10 22:27
professionalMycroft Holmes1-Jun-10 22:27 
Questionpull method of crystal report..promptin for password. Pin
VB.Net Developer31-May-10 20:12
VB.Net Developer31-May-10 20:12 
AnswerRe: pull method of crystal report..promptin for password. Pin
Adam R Harris17-Jun-10 6:03
Adam R Harris17-Jun-10 6:03 
Questionhow set password in code Pin
Mohammad Barzanooni27-May-10 18:07
Mohammad Barzanooni27-May-10 18:07 
AnswerRe: how set password in code Pin
Peace ON27-May-10 22:07
Peace ON27-May-10 22:07 
QuestionHelp with label printing SDK from Seagull bartender Pin
ziscoooo27-May-10 2:51
ziscoooo27-May-10 2:51 
AnswerRe: Help with label printing SDK from Seagull bartender Pin
Dave Kreskowiak27-May-10 5:51
mveDave Kreskowiak27-May-10 5:51 
GeneralRe: Help with label printing SDK from Seagull bartender Pin
ziscoooo27-May-10 12:32
ziscoooo27-May-10 12:32 
Question3 buttons in a datagridview cell Pin
jogisarge25-May-10 5:38
jogisarge25-May-10 5:38 
AnswerRe: 3 buttons in a datagridview cell Pin
Simon_Whale25-May-10 5:44
Simon_Whale25-May-10 5:44 
QuestionIncapable of listening for Mouse Events on UserControl Pin
Draekz20-May-10 11:53
Draekz20-May-10 11:53 
AnswerRe: Incapable of listening for Mouse Events on UserControl Pin
Luc Pattyn20-May-10 12:59
sitebuilderLuc Pattyn20-May-10 12:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.