發表文章

目前顯示的是 3月, 2012的文章

Silverlight – InkPresenter 上程式畫圓

圖片
一直以來都是使用 component 來畫圓,InkPresenter 只提供由點來組成各種形狀,那需自行畫圓時,如何取得圓弧上各點的X,Y座標呢?X: cos(角度) * r, Y: sin(角度) * r,利用此公式就可以取得圓弧上各點的X,Y座標. XAML: <InkPresenter x:Name="ink" Width="600" Height="600" MouseLeftButtonUp="ink_MouseLeftButtonUp"> </InkPresenter> C#: System.Windows.Ink.Stroke newStroke = new System.Windows.Ink.Stroke(); newStroke.DrawingAttributes.Color = Color.FromArgb(255, 0, 0, 0); newStroke.DrawingAttributes.Width = 1; newStroke.DrawingAttributes.Height = 1; for (int i = 0; i <= 360; i+=5) { newStroke.StylusPoints.Add( new StylusPoint() { X = 300 - 300 * Math.Cos(Math.PI * i / 180), Y = 300 - 300 * Math.Sin(Math.PI * i / 180) } ); } ink.Strokes.Add(newStroke);   其結果如下所示:

[轉貼] - Flash vs Silverlight: Simple Drawing

圖片
With the advantage of rendering speed, Flash and Silverlight can provide a richer experience in drawing and image filtering. Moreover, by using the Timer Event, real time replay of drawing bring us into another generation of art. Recently, I got quite many application requests. I think a implementation list will be made to give you a better idea what will happen in the next few days. Comparison Flash implementation: 1 hour 10 minutes   Silverlight implementation: 1 hour 30 minutes  What’s the difference? Line Drawing: moveTo, LineTo [AS3] vs System.Windows.Shapes.Line [C#] Source codes    Simple Drawing [Flash 9, AS3] (16.2 KiB, 2,278 hits)    Simple Drawing [Silverlight 2, C#] (48.8 KiB, 3,360 hits) Flash Silverlight Line: moveTo, LineTo [AS3] vs System.Windows.Shapes.Line [C#] I think drawing in AS3 is pretty straight forward and easy. It’s because all of the drawing librar

jQuery – 在 Form 做submit 時附加額外的 Parameters

當 Form 在 submit 時要附加額外的 Parameters 時,在 jQuery 中可以使用 appendTo Function 來達到這個功能,提供一下範例供參考. $("<input />").attr("type", "hidden").attr("name", "myname").attr("value", myvalue).appendTo(".formCssClass"); 在 Form 的 javascript 的 onsumbit 所觸發的 Function 加入上面的程式碼即可達到此功能. PS : 當name使用 array (ex: myname[] ) 時,回傳至 Server 端的資料則像 Select 設為 multi 的方式是一樣的.

jQuery – 控制 Table 中 Row 的順序

當想要控制 Table 中 Row 的順序時,在其 jQuery 的部份如何實作呢?在此提供實作的程式碼供參考. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=BIG5"> <script type="text/javascript" src="js/jquery-1.5.2.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#testGrid > tbody > tr").bind("click", function() { $("#testGrid > tbody > tr").css("background-color", "").removeAttr("selected"); $(this).css("background-color", "red").attr("selected", "true"); }); $("#top").bind("click", function() { if ($("#testGrid > tbody > tr[selected=true]").size() > 0) { if (!$("#testGrid > tbody > tr:first").attr("

Flex – 與 Javascript 互相溝通

Flex 在擷取資料時一般都是自行內部使用 Http Service , Remote Object … 等等方式來取得,但如需用 Javascript 傳遞資料時,那需如何實作呢?下面程式碼提供此範例供參考. <?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2008/03/09/calling-javascript-functions-from-your-flex-applications-using-the-externalinterface-api/ --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"> <mx:Script> <![CDATA[ private function callJavaScript():void { ExternalInterface.call("sayHelloWorld"); } ]]> </mx:Script> <mx:Button label="Say 'Hello World'" click="callJavaScript();" /> </mx:Application> Javascript: <script language="JavaScript" type="text/javascript"> function sayHelloW

Flex – 改變 DividedBox 的 icon 及提供 Double Click 縮合功能

圖片
在 Flex 中 HDividedBox 及 VDividedBox 提供了讓使用者可以自由調整切割視窗的大小,但並不提供 Double Click 的功能.故如需此功能則需 extends DividedBox,在此提供另一種作法. 1. 加入下面的程式碼 hdividedBox.getDividerAt(0).toolTip = "Double click to hide criteria."; hdividedBox.getDividerAt(0).doubleClickEnabled = true; hdividedBox.getDividerAt(0).addEventListener(MouseEvent.DOUBLE_CLICK, doubleClickHandler); protected function doubleClickHandler(event:MouseEvent):void { if (hdividedBox.getDividerAt(0).x <= 50) { criteriaNav.minWidth = 360; criteriaNav.maxWidth = 360; hdividedBox.moveDivider(0, 360); hdividedBox.setStyle("dividerSkin", rightImg); hdividedBox.getDividerAt(0).toolTip = "Double click to hide criteria."; } else { criteriaNav.minWidth = 0; criteriaN

Flex – ProgressBar 隱藏 Label 的方法

圖片
當 Application 在跟 Server 擷取資料時,一般都會使用 Busy Indicator 來告知有動作正在執行,但使用 Flex 建立 Web Application 時並沒有提供此 component,故可以使用 ProgressBar 來達到此效果. 一般 ProgressBar 中包含了 Label 這個 Component,那如果把它給 hidden 呢?可以使用下面的屬性來設定讓它 Hidden(紅色所mask的部份). <mx:ProgressBar id="progressBar" indeterminate="true" width="100%"                        label="" labelPlacement="right" labelWidth="0" horizontalGap="0" /> 效果如下所示:

Java - 顯示 Exception 中 StackTrace 的訊息

當在 coding 時使用 try - catch 來捕捉發生的 Exception,可是如何完整的 Exception 中的訊息抓出來呢?Exception 中提供了 printStackTrace Method 可以來取得全部的訊息.那下面的範例可以取得 Exception 中所有的訊息. public class ExceptionManager { public static String getPrintStackTrace(Exception ex) { Writer result = new StringWriter(); PrintWriter printWriter = new PrintWriter(result); ex.printStackTrace(printWriter); return result.toString(); } }

Java – Hibernate顯示 SQL 語法及 Parameter Values

在使用 Hibernate 時因它的語法有二種.一種是 HQL,另一種為 SQL,但如何讓 Hibernate 顯示最後執行 SQL 語法呢?可以在 hibernate.cfg.xml 中設定來達成此功能. 1. show_sql 顯示所有產生的 SQL 語法至 console. <!--hibernate.cfg.xml --> <property name="show_sql">true</property> <!--Output --> Hibernate: INSERT INTO mkyong.stock_transaction (CHANGE, CLOSE, DATE, OPEN, STOCK_ID, VOLUME) VALUES (?, ?, ?, ?, ?, ?) 2. format_sql 讓產生出的 SQL 語法可讀性更高 <!--hibernate.cfg.xml --> <property name="format_sql">true</property> <!--Output --> Hibernate: INSERT INTO mkyong.stock_transaction (CHANGE, CLOSE, DATE, OPEN, STOCK_ID, VOLUME) VALUES (?, ?, ?, ?, ?, ?) 3. use_sql_comments Hibernate會加入 comments 至產生出的 SQL 語法 <!--hibernate.cfg.xml --> <property name="use_sql_comments">true</property> <!--Output --> Hibernate: /* insert com.mkyong.common.StockTransaction */ INSERT INTO mkyong.stock_transaction