Pages - Menu

2016年5月20日 星期五

Google Chrome,前端(javascript)除錯方法

Chrome瀏覽器簡易除錯方式,
本篇圖片眾多,請小心服用。

2016年5月18日 星期三

將chart 轉圖表列印 使用e.Graphics.DrawString

沒想到會有自己手動刻報表的時候,使用winform開發,
要列印報表。需加上chart,本來想使用rdlc作為列印的工作,
但他的chart太陽春了,很多功能做不到,只好拿原本的mschart轉成圖片後塞進去。
刻的過程,通常會寫在printDocument.printPage裡面
先寫幾個常用到的。
1.計算title字串的寬度有多少,把width改成height就是高度了。
e.Graphics.MeasureString(title,New Font("Arial", 24.0F, FontStyle.Bold), e.MarginBounds.Width).Width
2.使用字型的大小去算高度
dim ypos as integer = New Font("Arial", 16.0F, FontStyle.Underline).GetHeight
3.劃線:
先建立筆的顏色、寬度。再來是實線的長度、虛線的長度。
指定線條的種類為自訂,也可以設定實線、虛線
傳入自己設定的虛線陣列。
畫出
Dim LinePen As New Pen(Color.Black, 1)
Dim lineDash As Single() = {10, 2}  '實線長度、虛線長度(loop)
LinePen.DashStyle = Drawing2D.DashStyle.Custom
LinePen.DashPattern = lineDash
e.Graphics.DrawLine(LinePen, New Point(e.MarginBounds.Left, yPos), New PointF(e.MarginBounds.Right, yPos))

4.建立字串\t,拿來對齊使用,vb需使用vbtab,如果在c#可直接使用\t即可。
os:為了讓同事能夠維護只能乖乖寫VB,言下之意就是我遲早會勞跑XD
e.Graphics.DrawString(String.Format("Cpk製程能力總和指數:{0}\t{1}", txtCpk.Text, txtCpkLv.Text).Replace("\t", vbTab), New Font(dg.Font, FontStyle.Bold), Brushes.Black,e.MarginBounds.Left + 261, yPos)
string.format("{1}{0}{2}{0}",a,vbTab,2,vbTab)

5.畫datagrid標題列
For Each GridCol As DataGridViewColumn In dg.Columns
                            e.Graphics.FillRectangle(New SolidBrush(Color.LightGray), New Rectangle(CInt(arrColumnLeft(iCount)),
                                                    iTopMargin, CInt(arrColumnWidth(iCount)), iHeaderHeight))                            e.Graphics.DrawRectangle(Pens.Black, New Rectangle(CInt(arrColumnLeft(iCount)), iTopMargin,
                                                                               CInt(arrColumnWidth(iCount)), iHeaderHeight))

                            e.Graphics.DrawString(GridCol.HeaderText, GridCol.InheritedStyle.Font,
                                                  New SolidBrush(GridCol.InheritedStyle.ForeColor),
                                                  New RectangleF(CInt(arrColumnLeft(iCount)), iTopMargin,
                                                                 CInt(arrColumnWidth(iCount)), iHeaderHeight), strFormat)
                            iCount += 1
                        Next


6.將chart轉成圖檔
'將chart轉成圖檔
            dataChart.DrawToBitmap(bmp, New Rectangle(0, 0, dataChart.Width, dataChart.Height))
            e.Graphics.DrawImage(DirectCast(dest_bmp, Image), e.PageBounds.Left + 20, yPos)

2016年5月17日 星期二

MsChart基本參數設定

很久很久沒用,寫網頁都直接用flotchart了。
偏偏這次是寫winForm只好拿mschart出來刻了。
有幾個重點的備註一下。
在做chart的時候有發現,控制項跟裡面的區域沒有塞滿。
後來才發現是auto的關係,現在強制指定變成95跟94,這是百分比。
要讓X軸從0開始,要設定最小 minimum=0,不然都是從1開始

       dataChart.Series("Series1").Points.Clear()
        dataChart.ChartAreas.Clear()
        dataChart.ChartAreas.Add("ChartArea1")
        Dim arrWT As Decimal() = CommonHelp.GetTypeStd(txtStd.Text)
        Dim intWT_std = arrWT(0), intWT_T = arrWT(1)
        Dim ChtLSL = intWT_std - intWT_T, ChtTGT = intWT_std, ChtUSL = intWT_std + intWT_T
        Dim chartMin = chartRange(intWT_T)(0), chartMax = chartRange(intWT_T)(1)
        '設定MainCht
        With dataChart
           
            .Series("Series1").MarkerStyle = MarkerStyle.Circle
            .ChartAreas(0).AxisX.MajorGrid.Enabled = False
            .ChartAreas(0).AxisY.MajorGrid.Enabled = False
            .ChartAreas(0).AxisX.MajorTickMark.Enabled = False
            .ChartAreas(0).AxisY.MajorTickMark.Enabled = False
            .ChartAreas(0).AxisX.LabelStyle.ForeColor = Color.Black
            .ChartAreas(0).InnerPlotPosition.Auto = True
            .Legends.Clear()
            '最大、最小
            .ChartAreas(0).AxisY.Minimum = ChtLSL - 20
            .ChartAreas(0).AxisY.Maximum = ChtUSL + 20

            '把圖表駔標的左右兩邊空白去除
            .ChartAreas(0).AxisX.IsMarginVisible = True
            .ChartAreas(0).AxisY.IsMarginVisible = True

            'X軸最大的資料點總數
            .ChartAreas(0).AxisX.Maximum = 100
            'X軸從0開始
            .ChartAreas(0).AxisX.Minimum = 0
            .ChartAreas(0).AxisX.Interval = 10

            '塞滿mschart
            .ChartAreas(0).Position.Width = 95
            .ChartAreas(0).Position.Height = 90
            ''Y軸標籤
            'first row are dummy labels to suppress axis numberics
            '.ChartAreas(0).AxisY.CustomLabels.Add(30, 40, "", 0, LabelMarkStyle.LineSideMark)
            .ChartAreas(0).AxisY.CustomLabels.Add(ChtLSL, ChtLSL + 1, "LSL(" & ChtLSL.ToString & ")")  'LSL
            .ChartAreas(0).AxisY.CustomLabels.Add(ChtTGT, ChtTGT + 1, "TGT(" & ChtTGT.ToString & ")")  'TGT
            .ChartAreas(0).AxisY.CustomLabels.Add(ChtUSL, ChtUSL + 1, "USL(" & ChtUSL.ToString & ")")  'USL
            .ChartAreas(0).AxisY.LabelAutoFitStyle = LabelAutoFitStyles.None

            'Set series chart type
            .Series("Series1").ChartType = SeriesChartType.Point
            ''加橫線
            For LineRow As Integer = 1 To 3
                Dim sl1 As StripLine = New StripLine
                sl1.BackColor = Color.Black
                sl1.StripWidth = 0.25
                Select Case LineRow
                    Case 1
                        sl1.IntervalOffset = ChtLSL
                    Case 2
                        sl1.IntervalOffset = ChtTGT
                    Case 3
                        sl1.IntervalOffset = ChtUSL
                End Select
                .ChartAreas(0).AxisY.StripLines.Add(sl1)
            Next
        End With

2016年5月11日 星期三

Sublime Text 3 ,加入右鍵選單

初步的安裝請先參考保哥的文章:這裡
由於習慣了在文件上按右鍵,開啟文件,然後Sublime沒有這個功能,
只好手動自己加了。
首先執行Regedit
路徑為:
image0001
在shell底下建立機碼(此名稱能隨自己意思更換),
但再底下的就必須取名為Command。
再來將值修改成檔案的路徑位置
image0004
記得要加上%1(數字)。好了之後現在按右鍵,就會出現選項了。
但前面沒有icon,沒辦法一眼辨認出來。所以繼續加上ico來用。
在剛剛命名的地方加上 字串值,取名為Icon
數值內容就直接抓你ico的位置。
image0003
完成收工

2016年5月6日 星期五

C# regex 正規表示法,懶人版

最近又需要正規表示法,查了之後才發現,要寫一長串阿…
寫成function方便使用。前面丟『來源字串』,後面丟『規則』。
回傳List<string>。
可使用toArray 轉成陣列後,假如前後有『, 』,可使用 trim(‘,') ,將前後的『,』刪除。