FolderWidget/frmMain.cs
/// <summary>
/// Add icons, and set dynamic form size
/// </summary>
Add icons, and set dynamic form size
Add icons and set dynamic form size
private void InitFormFilesAndButtons()
        {
            ClearData();
            m_iconsData = clsFileManager.GetInitData();
            this.Height = m_height + (50 * ((int)m_iconsData.Rows.Count / 3));
            tblIcons.RowCount = (m_iconsData.Rows.Count / 3) + 1;
            if (m_iconsData.Rows.Count % 3 == 0)
            {
                this.Height = this.Height - 50;
                tblIcons.RowCount--;
            }
            this.Size = new Size(this.Width, this.Height);
            this.FormBorderStyle = FormBorderStyle.None;
            tblIcons.Dock = DockStyle.Fill;
            for (int i = 0; i < tblIcons.RowCount; i++)
            {
                tblIcons.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
            }
            int counter = 0;
            bool stopAndRestart = false;
            for (int row = 0; row < tblIcons.RowCount; row++)
            {
                for (int column = 0; column < tblIcons.ColumnCount; column++)
                {
                    if (m_iconsData.Rows.Count > counter)
                    {
                        string path = m_iconsData.Rows[counter]["Path"].ToString();
                        foreach (var item in path.Split(','))
                        {
                            if (!File.Exists(item) && !Directory.Exists(item))
                            {
                                stopAndRestart = true;
                            }
                        }
                        if (stopAndRestart)
                        {
                            var res = (m_iconsData.AsEnumerable().Where(dr => dr.Field<string>("Path") == path).FirstOrDefault()) as DataRow;
                            if (!string.IsNullOrEmpty(res["Icon"].ToString()))
                            {
                                clsFileManager.DeleteIcon(res["Icon"].ToString());
                            }
                            m_iconsData.Rows.Remove(res);
                            clsFileManager.ReplaceXMLFile(m_iconsData);
                            break;
                        }
                        else
                        {
                            tblIcons.Controls.Add(MakeDynamicButton(m_iconsData.Rows[counter]), column, row);
                            counter++;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (stopAndRestart)
                {
                    break;
                }
            }
            if (stopAndRestart)
            {
                InitFormFilesAndButtons();
                return;
            }
            if (m_iconsData.Rows.Count == 0)
            {
                lblFileName.Text = "Drag Something";
            }
            else
            {
                lblFileName.Text = string.Empty;
            }
            Region = Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 10, 10));
            DoubleBuffered = true;
        }
private void InitFormFilesAndButtons ( ) { ClearData ( ) ; m_iconsData = clsFileManager . GetInitData ( ) ; this . Height = m_height + ( 50 * ( ( int ) m_iconsData . Rows . Count / 3 ) ) ; tblIcons . RowCount = ( m_iconsData . Rows . Count / 3 ) + 1 ; if ( m_iconsData . Rows . Count % 3 == 0 ) { this . Height = this . Height - 50 ; tblIcons . RowCount -- ; } this . Size = new Size ( this . Width , this . Height ) ; this . FormBorderStyle = FormBorderStyle . None ; tblIcons . Dock = DockStyle . Fill ; for ( int i = 0 ; i < tblIcons . RowCount ; i ++ ) { tblIcons . RowStyles . Add ( new RowStyle ( SizeType . Percent , 100 ) ) ; } int counter = 0 ; bool stopAndRestart = false ; for ( int row = 0 ; row < tblIcons . RowCount ; row ++ ) { for ( int column = 0 ; column < tblIcons . ColumnCount ; column ++ ) { if ( m_iconsData . Rows . Count > counter ) { string path = m_iconsData . Rows [ counter ] [ " " ] . ToString ( ) ; foreach ( var item in path . Split ( ' ' ) ) { if ( ! File . Exists ( item ) && ! Directory . Exists ( item ) ) { stopAndRestart = true ; } } if ( stopAndRestart ) { var res = ( m_iconsData . AsEnumerable ( ) . Where ( dr => dr . Field < string > ( " " ) == path ) . FirstOrDefault ( ) ) as DataRow ; if ( ! string . IsNullOrEmpty ( res [ " " ] . ToString ( ) ) ) { clsFileManager . DeleteIcon ( res [ " " ] . ToString ( ) ) ; } m_iconsData . Rows . Remove ( res ) ; clsFileManager . ReplaceXMLFile ( m_iconsData ) ; break ; } else { tblIcons . Controls . Add ( MakeDynamicButton ( m_iconsData . Rows [ counter ] ) , column , row ) ; counter ++ ; } } else { break ; } } if ( stopAndRestart ) { break ; } } if ( stopAndRestart ) { InitFormFilesAndButtons ( ) ; return ; } if ( m_iconsData . Rows . Count == 0 ) { lblFileName . Text = " " ; } else { lblFileName . Text = string . Empty ; } Region = Region . FromHrgn ( CreateRoundRectRgn ( 0 , 0 , Width , Height , 10 , 10 ) ) ; DoubleBuffered = true ; }
Add icons, and set dynamic form size
Add icons and set dynamic form size
//Round Form