示例#1
0
 /// <summary>
 /// for evnet change backcolor
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 /// <remarks>
 /// Created by	: cuongvd G3 fsoftHCM
 /// create date	: 18-jan-2007
 /// </remarks>
 private void SetHeaderCellFormat(object sender, DataGridFormatCellEventArgs e)
 {
     try
     {
         e.BackBrush = brColor;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#2
0
        //overridden to fire BoolChange event and Formatting event
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
        {
            int colNum = this.DataGridTableStyle.GridColumnStyles.IndexOf(this);

            //used to handle the boolchanging
            ManageBoolValueChanging(rowNum, colNum);

            //fire formatting event
            DataGridFormatCellEventArgs  e     = null;
            DataGridGetSizeCellEventArgs eSize = null;
            bool callBaseClass = true;

            if (SetCellFormat != null)
            {
                e = new DataGridFormatCellEventArgs(rowNum, colNum, this.GetColumnValueAtRow(source, rowNum));
                SetCellFormat(this, e);
                if (e.BackBrush != null)
                {
                    backBrush = e.BackBrush;
                }
                callBaseClass = e.UseBaseClassDrawing;
            }
            if (GetSizeCell != null)
            {
                eSize = new DataGridGetSizeCellEventArgs(bounds);
                GetSizeCell(this, eSize);
            }
            if (callBaseClass)
            {
                base.Paint(g, bounds, source, rowNum, backBrush, new SolidBrush(Color.Red), alignToRight);
            }

            //clean up
            if (e != null)
            {
                if (e.BackBrushDispose)
                {
                    e.BackBrush.Dispose();
                }
                if (e.ForeBrushDispose)
                {
                    e.ForeBrush.Dispose();
                }
                if (e.TextFontDispose)
                {
                    e.TextFont.Dispose();
                }
            }
        }
示例#3
0
 /// <summary>
 /// for evnet change backcolor
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 /// <remarks>
 /// Created by	: cuongvd G3 fsoftHCM
 /// create date	: 18-jan-2007
 /// </remarks>
 private void SetHeaderCellFormat(object sender, DataGridFormatCellEventArgs e)
 {
     try
     {
         e.BackBrush = brColor;
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#4
0
        //used to fire an event to retrieve formatting info
        //and then draw the cell with this formatting info
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
        {
            DataGridFormatCellEventArgs e = null;

                bool callBaseClass = true;

                //fire the formatting event
                if(SetCellFormat != null)
                {
                    int col = this.DataGridTableStyle.GridColumnStyles.IndexOf(this);
                    e = new DataGridFormatCellEventArgs(rowNum, col, this.GetColumnValueAtRow(source, rowNum));
                    SetCellFormat(this, e);
                    if(e.BackBrush != null)
                        backBrush = e.BackBrush;

                    //if these properties set, then must call drawstring
                    if(e.ForeBrush != null || e.TextFont != null)
                    {
                        if(e.ForeBrush == null)
                            e.ForeBrush = foreBrush;
                        if(e.TextFont == null)
                            e.TextFont = this.DataGridTableStyle.DataGrid.Font;
                        g.FillRectangle(backBrush, bounds);
                        Region saveRegion = g.Clip;
                        Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height);
                        using(Region newRegion = new Region(rect))
                        {
                            g.Clip = newRegion;
                            int charWidth = (int) Math.Ceiling(g.MeasureString("c", e.TextFont, 20, StringFormat.GenericTypographic).Width);

                            string s = this.GetColumnValueAtRow(source, rowNum).ToString();
                            int maxChars = Math.Min(s.Length,  (bounds.Width / charWidth));

                            try
                            {
                                g.DrawString(s.Substring(0, maxChars), e.TextFont, e.ForeBrush, bounds.X, bounds.Y + 2);
                            }
                            catch(Exception ex)
                            {
                                Console.WriteLine(ex.Message.ToString());
                            } //empty catch
                            finally
                            {
                                g.Clip = saveRegion;
                            }
                        }
                        callBaseClass = false;
                    }

                    if(!e.UseBaseClassDrawing)
                    {
                        callBaseClass = false;
                    }
                }
                if(callBaseClass)
                    base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);

                //clean up
                if(e != null)
                {
                    if(e.BackBrushDispose)
                        e.BackBrush.Dispose();
                    if(e.ForeBrushDispose)
                        e.ForeBrush.Dispose();
                    if(e.TextFontDispose)
                        e.TextFont.Dispose();
                }
        }
示例#5
0
        //overridden to fire BoolChange event and Formatting event
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
        {
            int colNum = this.DataGridTableStyle.GridColumnStyles.IndexOf(this);

                //used to handle the boolchanging
                ManageBoolValueChanging(rowNum, colNum);

                //fire formatting event
                DataGridFormatCellEventArgs e = null;
                DataGridGetSizeCellEventArgs eSize = null;
                bool callBaseClass = true;
                if(SetCellFormat != null)
                {
                    e = new DataGridFormatCellEventArgs(rowNum, colNum, this.GetColumnValueAtRow(source, rowNum));
                    SetCellFormat(this, e);
                    if(e.BackBrush != null)
                        backBrush = e.BackBrush;
                    callBaseClass = e.UseBaseClassDrawing;
                }
                if(GetSizeCell != null)
                {
                    eSize = new DataGridGetSizeCellEventArgs(bounds);
                    GetSizeCell(this,eSize);
                }
                if(callBaseClass)
                    base.Paint(g, bounds, source, rowNum, backBrush, new SolidBrush(Color.Red), alignToRight);

                //clean up
                if(e != null)
                {
                    if(e.BackBrushDispose)
                        e.BackBrush.Dispose();
                    if(e.ForeBrushDispose)
                        e.ForeBrush.Dispose();
                    if(e.TextFontDispose)
                        e.TextFont.Dispose();
                }
        }
示例#6
0
        //used to fire an event to retrieve formatting info
        //and then draw the cell with this formatting info
        protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
        {
            DataGridFormatCellEventArgs e = null;

            bool callBaseClass = true;

            //fire the formatting event
            if (SetCellFormat != null)
            {
                int col = this.DataGridTableStyle.GridColumnStyles.IndexOf(this);
                e = new DataGridFormatCellEventArgs(rowNum, col, this.GetColumnValueAtRow(source, rowNum));
                SetCellFormat(this, e);
                if (e.BackBrush != null)
                {
                    backBrush = e.BackBrush;
                }

                //if these properties set, then must call drawstring
                if (e.ForeBrush != null || e.TextFont != null)
                {
                    if (e.ForeBrush == null)
                    {
                        e.ForeBrush = foreBrush;
                    }
                    if (e.TextFont == null)
                    {
                        e.TextFont = this.DataGridTableStyle.DataGrid.Font;
                    }
                    g.FillRectangle(backBrush, bounds);
                    Region    saveRegion = g.Clip;
                    Rectangle rect       = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height);
                    using (Region newRegion = new Region(rect))
                    {
                        g.Clip = newRegion;
                        int charWidth = (int)Math.Ceiling(g.MeasureString("c", e.TextFont, 20, StringFormat.GenericTypographic).Width);

                        string s        = this.GetColumnValueAtRow(source, rowNum).ToString();
                        int    maxChars = Math.Min(s.Length, (bounds.Width / charWidth));

                        try
                        {
                            g.DrawString(s.Substring(0, maxChars), e.TextFont, e.ForeBrush, bounds.X, bounds.Y + 2);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message.ToString());
                        }                                 //empty catch
                        finally
                        {
                            g.Clip = saveRegion;
                        }
                    }
                    callBaseClass = false;
                }

                if (!e.UseBaseClassDrawing)
                {
                    callBaseClass = false;
                }
            }
            if (callBaseClass)
            {
                base.Paint(g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
            }

            //clean up
            if (e != null)
            {
                if (e.BackBrushDispose)
                {
                    e.BackBrush.Dispose();
                }
                if (e.ForeBrushDispose)
                {
                    e.ForeBrush.Dispose();
                }
                if (e.TextFontDispose)
                {
                    e.TextFont.Dispose();
                }
            }
        }