Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > .NET Framework > Forum > C# WinApp linkLabel อยากให้ เวลาเปิดไฟล์ที่ไม่รู้จัก แล้ว แจ้งเตือน ครับ



 

C# WinApp linkLabel อยากให้ เวลาเปิดไฟล์ที่ไม่รู้จัก แล้ว แจ้งเตือน ครับ

 



Topic : 133849



โพสกระทู้ ( 4,437 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook



โค้ดครับ

Code (C#)
 System.Diagnostics.Process.Start(linkLabel1.Links[0].LinkData.ToString());


ห

2

อยากให้มันขึ้นแบบนี้ กรณี ที่ไม่มีโปรแกรมเปิด ครับ
3



Tag : .NET, Win (Windows App), C#







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2019-07-06 11:43:20 By : lamaka.tor View : 838 Reply : 4
 

 

No. 1



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


https://stackoverflow.com/questions/10174156/open-file-with-associated-application






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2019-07-06 12:07:55 By : Chaidhanan
 


 

No. 2



โพสกระทู้ ( 1,458 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Facebook Blogger

ที่มันหาไฟล์ไม่เจอเพราะออปเจ็ก Link​Collection ยังไม่มีข้อมูล(ลิงค์) ต้องเพิ่มลิงค์เข้าไปก่อนครับ ด้วยเมธอด Add() ของคลาส Link​Collection

Link​Label.​Link​Collection.​Add Method
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2019-07-06 13:00:42 By : PhrayaDev
 

 

No. 3



โพสกระทู้ ( 4,437 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ขอบคุณมากครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2019-07-07 09:28:15 By : lamaka.tor
 


 

No. 4



โพสกระทู้ ( 4,437 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

โค้ด TextboxFileDialog ครับ

Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Versioning;

namespace TORServices.FormsTor
{
    public partial class TextboxFileDialog : UserControl
    {
        /// <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._Button = new System.Windows.Forms.Button();
            this.panel2 = new System.Windows.Forms.Panel();
            this._Lnk = new System.Windows.Forms.LinkLabel();
            this.panel2.SuspendLayout();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
            this.panel1.Location = new System.Drawing.Point(273, 0);
            this.panel1.Margin = new System.Windows.Forms.Padding(5);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(11, 33);
            this.panel1.TabIndex = 5;
            // 
            // _Button
            // 
            this._Button.Cursor = System.Windows.Forms.Cursors.Hand;
            this._Button.Dock = System.Windows.Forms.DockStyle.Right;
            this._Button.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
            this._Button.Image = global::TORServices.Properties.Resources.search_button32x32;
            this._Button.Location = new System.Drawing.Point(284, 0);
            this._Button.Margin = new System.Windows.Forms.Padding(5);
            this._Button.Name = "_Button";
            this._Button.Size = new System.Drawing.Size(34, 33);
            this._Button.TabIndex = 4;
            this._Button.Click += new System.EventHandler(this._Button_Click);
            // 
            // panel2
            // 
            this.panel2.BackColor = System.Drawing.Color.White;
            this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.panel2.Controls.Add(this._Lnk);
            this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panel2.Location = new System.Drawing.Point(0, 0);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(273, 33);
            this.panel2.TabIndex = 6;
            // 
            // _Lnk
            // 
            this._Lnk.AutoSize = true;
            this._Lnk.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
            this._Lnk.Location = new System.Drawing.Point(5, 4);
            this._Lnk.Name = "_Lnk";
            this._Lnk.Size = new System.Drawing.Size(94, 24);
            this._Lnk.TabIndex = 6;
            this._Lnk.TabStop = true;
            this._Lnk.Text = "linkLabel1";
            this._Lnk.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this._Lnk_LinkClicked);
            // 
            // TextboxFileDialog
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.panel2);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this._Button);
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
            this.Margin = new System.Windows.Forms.Padding(5);
            this.Name = "TextboxFileDialog";
            this.Size = new System.Drawing.Size(318, 33);
            this.panel2.ResumeLayout(false);
            this.panel2.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.Panel panel1;
        public System.Windows.Forms.Button _Button;
        private System.Windows.Forms.Panel panel2;
        private System.Windows.Forms.LinkLabel _Lnk;

        public TextboxFileDialog()
        {
            InitializeComponent();
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(222)));
           // _Lnk.BackColor = _txt.BackColor;
           // _Lnk.Text = _txt.Text;
        }

        #region _Property
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.Category("TOR Setting")]
        public override string Text
        {
            get
            {
                return this._Lnk.Text;
            }
            set
            {
                this._Lnk.Text = value;
               // this.Text = value;
                _Lnk.Links.Clear();
                _Lnk.Links.Add(0, _Lnk.Text.Length, FullPath);
            }
        }
        [Localizable(true)]
        public Image ImageButton
        {
            [ResourceExposure(ResourceScope.Machine)]
            [ResourceConsumption(ResourceScope.Machine)]
            get
            {
                return _Button.Image;
            }
            set
            {
                _Button.Image = value; Invalidate();
            }
        }

        [
         DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
         RefreshProperties(RefreshProperties.All),
         ParenthesizePropertyName(true)
         ]
        public ControlBindingsCollection DataBindings
        {
            get
            {
                ControlBindingsCollection bindings = (ControlBindingsCollection)this._Lnk.DataBindings;
                if (bindings == null)
                {
                    bindings = new ControlBindingsCollection(this);
                }
                return bindings;
            }

        }

        private bool oponly = true;
        [System.ComponentModel.Description("Set OpenOnly on Text"),
         System.ComponentModel.Browsable(true),
         System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always),
         System.ComponentModel.Category("TOR Setting")]
        public bool OpenOnly
        {
            get { return oponly; }
            set { oponly = value; }
        }

        private string _Path;
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)]
        [System.ComponentModel.DefaultValue(@"C:")]
        [System.ComponentModel.Category("TOR Setting")]
        [System.ComponentModel.Description("Open Dialog is dispalyed and on success the contents of the Cell is replaced with the new  path.")]
        public string Directory
        {
            get
            {
                return _Path;
            }
            set
            {
                _Path = value;
            }
        }
        private string _SubPath;
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)]
        [System.ComponentModel.DefaultValue("")]
        [System.ComponentModel.Category("TOR Setting")]
        [System.ComponentModel.Description("Open Dialog is dispalyed and on success the contents of the Cell is replaced with the new  path.")]
        public string SubDirectory
        {
            get
            {
                return _SubPath;
            }
            set
            {
                _SubPath = value;
            }
        }
        private string _Filter;
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Always)]
        [System.ComponentModel.DefaultValue("Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png" +
                                    "|txt files (*.txt)|*.txt" +
                                    "|Document files (*.doc, *.docx, *.xls,  *.xlsx, *.ppt, *.pptx, *.pdf )|*.doc, *.docx, *.xls,  *.xlsx, *.ppt, *.pptx, *.pdf " +
                                    "|Audio/Vdio files (*.AVI, *.XVID, *.DivX *.3GP *.MKV *.MP4 *.FLV *.MP3 *.DAT)|*.AVI, *.XVID, *.DivX *.3GP *.MKV *.MP4 *.FLV *.MP3 *.DAT" +
                                    "|All files (*.*)|*.*")]
        [System.ComponentModel.Category("TOR Setting")]
        [System.ComponentModel.Description("Open Dialog is dispalyed and on success the contents of the Cell is replaced with the new  path.")]
        public string Filter
        {
            get
            {
                return _Filter;
            }
            set
            {
                _Filter = value;
            }
        }
        private bool _showfullpath;
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.Category("TOR Setting")]
        [System.ComponentModel.Description("Open Full path directory")]
        public bool Showfullpath
        {
            get { return _showfullpath; }
            set
            {
                _showfullpath = value;
                if (_showfullpath == true)
                { Text = FullPath; }
                else
                {
                    if (System.IO.File.GetAttributes(FullPath).HasFlag(System.IO.FileAttributes.Directory))
                    {
                        Text = System.IO.Path.GetFileName(FullPath);
                    }
                    else
                    {
                        Text = "";
                    }
                }
            }
        }
        private Color _TextBackColor;
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.Category("TOR Setting")]
        public Color TextBackColor
        {
            get { return _TextBackColor; }
            set
            {
                panel2.BackColor = BackColor;
            }
        }
        private string FullDirectory
        {
            get
            {
                string directory = ((string.IsNullOrEmpty(Directory)) ? Application.StartupPath : Directory.Replace("AppPath", Application.StartupPath)) + ((_SubPath == "") ? "" : "\\" + _SubPath);
                directory = (!string.IsNullOrEmpty(System.IO.Path.GetPathRoot(directory))) ? directory : Application.StartupPath + "\\" + directory;
                directory = (directory.EndsWith("\\")) ? directory : directory + "\\";
                if (!System.IO.Directory.Exists(directory)) System.IO.Directory.CreateDirectory(directory);

                return directory;
            }
        }
        public string FullPath
        {
            get
            {
                // string path = (Showfullpath == true) ? Convert.ToString(this.Text) : FullDirectory + Convert.ToString(this.Text);
                string path =  FullDirectory + Convert.ToString(this.Text);
                return (string.IsNullOrEmpty(path)) ? Application.StartupPath : path;
            }
        }

        #endregion
        #region _EventArgs
        protected override void OnSizeChanged(EventArgs e)
        {
            if (this.Height != this.panel2.Height)
                this.Height = this.panel2.Height;
            _Button.Height = panel2.Height;
            _Button.Width = _Button.Height;
            base.OnSizeChanged(e);
        }
        protected override void OnForeColorChanged(EventArgs e)
        {
            _Lnk.ForeColor = ForeColor;
            base.OnForeColorChanged(e);

        }
        protected override void OnFontChanged(EventArgs e)
        {
            _Lnk.Font = Font;
            panel2.Font = Font;
            this.OnSizeChanged(e);
            // _Button.Font = Font;
        }
        public event EventHandler ButtonClick
        {
            add
            {
                _Button.Click += value;
            }
            remove
            {
                _Button.Click -= value;
            }
        }

        public event EventHandler ButtonDoubleClick
        {
            add
            {
                _Button.DoubleClick += value;
            }
            remove
            {
                _Button.DoubleClick -= value;
            }
        }
        public event EventHandler TextChanged
        {
            add
            {
                _Lnk.TextChanged += value;
            }
            remove
            {
                _Lnk.TextChanged -= value;
            }
        }

        public event EventHandler TextBoxDoubleClick
        {
            add
            {
                _Lnk.DoubleClick += value;
            }
            remove
            {
                _Lnk.DoubleClick -= value;
            }
        }
        #endregion



        private void _Lnk_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {

            if (_Lnk.Links.Count > 0)
            {
               // TORServices.PathFileTor.FileTor.OpenFile(FullPath);

                if (!System.IO.File.Exists(FullPath))
                    {
                        System.Windows.Forms.MessageBox.Show("Can't Find File " + FullPath);
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("Can't Open File " + FullPath);

                    }

              
            }
        }

        private void _Button_Click(object sender, EventArgs e)
        {

            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Filter = Filter;
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    using (SaveFileDialog dialog1 = new SaveFileDialog())
                    {
                        dialog1.InitialDirectory = FullDirectory;
                        dialog1.FileName = System.IO.Path.GetFileName(dialog.FileName);
                        dialog1.Filter = Filter;
                        if (dialog1.ShowDialog() == DialogResult.OK)
                        {
                            // SetPath(dialog.FileName);
                            this.Text =  System.IO.Path.GetFileName(dialog1.FileName);

                            if (dialog.FileName != dialog1.FileName)
                                System.IO.File.Copy(dialog.FileName, dialog1.FileName, true);
                        }

                    }

                }
            }
        }


       
    }
}




การใช้งานทั้งใน datagridview กับ ลากมาลงใน ฟอร์ม ครับ

33

ช่วยๆกันใช้ แล้วก็แก้ ให้มัน ดีๆขึ้น นะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2019-07-07 12:29:06 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : C# WinApp linkLabel อยากให้ เวลาเปิดไฟล์ที่ไม่รู้จัก แล้ว แจ้งเตือน ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่