Пример #1
0
        //タブコントロールのタブ部分ダブルクリック時に名前の編集
        private void tabControlEx_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            //Console.WriteLine("tabControlEx_MouseDoubleClick");
            TabEx tabEx = sender as TabEx;

            tabEx.EditTabText(tabEx.SelectedTab.Name);
        }
Пример #2
0
        //アプリケーションのドラッグアンドドロップ
        public void AppDragDrop(object sender, DragEventArgs e)
        {
            Console.WriteLine("AppDragDrop_Start");
            try
            {
                TabEx tabEx = sender as TabEx;

                //ファイルのドラッグアンドドロップ時
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    //ファイルの絶対パスと名前の取得
                    string[] files     = (string[])e.Data.GetData(DataFormats.FileDrop);
                    var      appPath   = files[0];
                    char[]   separator = new char[] { '\\' };
                    string[] arr       = appPath.Split(separator);

                    string appName;
                    if (arr[arr.Length - 1].Length > appNameMax)
                    {
                        appName = arr[arr.Length - 1].Substring(0, appNameMax);
                    }
                    else
                    {
                        appName = arr[arr.Length - 1];
                    }

                    //タブ情報ファイルの読み込み
                    var xmlDoc = new XmlDocument();
                    xmlDoc.Load(@"config.xml");
                    var tabNodes = xmlDoc.SelectNodes("tabs/tab");

                    //タブ情報ファイルの更新とアプリケーション表示用パネルの設置
                    for (var i = 0; i < tabNodes.Count; i++)
                    {
                        var tabId = ((XmlElement)tabNodes[i]).GetAttribute("id"); //tabタグのid

                        //現在選択中のタブとtabタグのidが一致した場合
                        if (tabEx.SelectedTab.Name == tabId)
                        {
                            var appNodes = xmlDoc.SelectNodes("tabs/tab[@id='" + i + "']/app"); //appタグ情報
                            var appId    = appNodes.Count;

                            //登録されているアプリケーションが最大値未満の場合
                            if (appId < appMax)
                            {
                                //タブ情報ファイルの更新
                                XmlNode rootNode   = xmlDoc.SelectSingleNode("tabs/tab[@id='" + i + "']");
                                XmlNode newAppNode = xmlDoc.CreateNode(XmlNodeType.Element, "app", null);
                                ((XmlElement)newAppNode).SetAttribute("id", appId.ToString());
                                XmlElement pathElement = xmlDoc.CreateElement("path");
                                XmlElement nameElement = xmlDoc.CreateElement("name");
                                XmlText    pathText    = xmlDoc.CreateTextNode(appPath);
                                //相対パスの登録
                                var curPath = System.Windows.Forms.Application.StartupPath;
                                if (appPath.Contains(curPath + "\\tool\\"))
                                {
                                    string   relPath    = null;
                                    string[] arrCurPath = curPath.Split(separator);
                                    for (int curPathLen = arrCurPath.Length; curPathLen < arr.Length; curPathLen++)
                                    {
                                        Console.WriteLine(arr[curPathLen]);
                                        relPath += "\\" + arr[curPathLen];
                                    }
                                    Console.Write(relPath);
                                    appPath  = relPath;
                                    pathText = xmlDoc.CreateTextNode(relPath);
                                }
                                XmlText nameText = xmlDoc.CreateTextNode(appName);
                                pathElement.AppendChild(pathText);
                                nameElement.AppendChild(nameText);
                                newAppNode.AppendChild(pathElement);
                                newAppNode.AppendChild(nameElement);
                                rootNode.AppendChild(newAppNode);
                                xmlDoc.Save(@"config.xml");

                                //アプリケーション表示用パネルの設置
                                PanelEx panelEx = new PanelEx();
                                panelEx.Location = new Point(25 + (appId % 6) * 100, 25 + (appId / 6) * 100);
                                panelEx.Size     = new Size(50, 50);
                                panelEx.Name     = i.ToString() + "_p_" + appId.ToString();
                                panelEx.SetPath(appPath, appName);
                                panelEx.ContextMenuStrip = appContextMenuStrip;

                                //アプリケーションのラベル設定
                                Label label = new Label();
                                label.Location = new Point(8 + (appId % 6) * 100, 78 + (appId / 6) * 100);
                                label.Size     = new Size(85, 25);
                                label.Name     = i.ToString() + "_l_" + appId.ToString();
                                if (appName.Length > appNameMax)
                                {
                                    label.Text = appName.Substring(0, appNameMax);
                                }
                                else
                                {
                                    label.Text = appName;
                                }
                                label.TextAlign = ContentAlignment.MiddleCenter;
                                label.AutoSize  = false;

                                //アプリケーションのテキストボックス設定
                                TextBox textBox = new TextBox();
                                textBox.Location = new Point(8 + (appId % 6) * 100, 78 + (appId / 6) * 100);
                                textBox.Size     = new Size(85, 50);
                                textBox.Name     = i.ToString() + "_t_" + appId.ToString();
                                if (appName.Length > appNameMax)
                                {
                                    textBox.Text = appName.Substring(0, appNameMax);
                                }
                                else
                                {
                                    textBox.Text = appName;
                                }
                                textBox.Visible   = false;
                                textBox.KeyPress += new KeyPressEventHandler(textBox_KeyPress);

                                tabEx.SelectedTab.Controls.Add(panelEx);
                                tabEx.SelectedTab.Controls.Add(label);
                                tabEx.SelectedTab.Controls.Add(textBox);
                            }
                            else
                            {
                                MessageBox.Show("アプリケーションをこれ以上登録できません。");
                            }
                        }
                    }
                }
            }
            catch (System.IO.FileNotFoundException ex)
            {
                //FileNotFoundExceptionをキャッチした時
                System.Console.WriteLine("設定ファイルが見つかりませんでした。");
                System.Console.WriteLine(ex.Message);
                MessageBox.Show("設定ファイルが見つかりませんでした。");
            }
            catch (System.IO.IOException ex)
            {
                //IOExceptionをキャッチした時
                System.Console.WriteLine("設定ファイルがロックされている可能性があります。");
                System.Console.WriteLine(ex.Message);
                MessageBox.Show("設定ファイルがロックされている可能性があります。");
            }
            catch (System.UnauthorizedAccessException ex)
            {
                //UnauthorizedAccessExceptionをキャッチした時
                System.Console.WriteLine("設定ファイルのアクセス許可がありません。");
                System.Console.WriteLine(ex.Message);
                MessageBox.Show("設定ファイルのアクセス許可がありません。");
            }
            catch (Exception ex)
            {
                MessageBox.Show("アプリケーションを実行できません。");
                MessageBox.Show(ex.Message);
            }
        }