Пример #1
0
        public static MdbusFile CreateFromFile(string fileName)
        {
            var mdbusFile = new MdbusFile();

            mdbusFile.FileName = fileName;
            return(mdbusFile);
        }
Пример #2
0
        private void AddFileToListBox(string mdbusLogFile)
        {
            var mdbusFile = MdbusFile.CreateFromFile(mdbusLogFile);

            listBoxCommands.Items.Clear();
            listBoxCommands.Items.AddRange(mdbusFile.GetAllCommands());
            // Display a shortened version of the file path above the list box
            // Found the solution here:
            // https://stackoverflow.com/questions/1764204/how-to-display-abbreviated-path-names-in-net
            // Thing to notice is that we have to make a copy of the string as the TextRenderer.MeasureText
            // actually changes the string even if .Net strings are immutable.
            var shortenFileName = string.Copy(mdbusLogFile);
            var size            = new Size(listBoxCommands.Width, 0);

            TextRenderer.MeasureText(shortenFileName, lblCommands.Font, size, TextFormatFlags.PathEllipsis | TextFormatFlags.ModifyString);
            lblCommands.Text = shortenFileName;
        }