C # Call cards. DLL to implement a graphical Licensing Program

Source: Internet
Author: User

Using system; <br/> using system. collections. generic; <br/> using system. componentmodel; <br/> using system. data; <br/> using system. drawing; <br/> using system. text; <br/> using system. windows. forms; <br/> using system. runtime. interopservices; <br/> using system. windows. forms. design; </P> <p> namespace getcards <br/>{< br/> Public partial class form1: form <br/> {<br/> [dllimport ("cards. DLL ")] <br/> Public static extern bool cdtinit (ref int width, ref int height); </P> <p> [dllimport (" cards. DLL ")] <br/> Public static extern void cdtterm (); </P> <p> [dllimport (" cards. DLL ")] <br/> Public static extern bool cdtdraw (intptr HDC, int X, int y, int card, int mode, long color ); <br/> // mode = 0 table front, 1 table back, color I tried a lot from 0-0xff000, it seems that no color changes </P> <p> // [dllimport ("cards. DLL ")] <br/> // public static extern bool cdtdrawext (intptr HDC, int X, int y, int dx, int dy, int card, int type, long color); </P> <p> // [dllimport ("cards. DLL ")] <br/> // public static extern bool cdtanimate (intptr HDC, int cardback, int X, int y, int frame ); </P> <p> int [] BB = new int [100]; <br/> Public form1 () <br/>{< br/> initializecomponent (); <br/>}</P> <p> private void form1_load (Object sender, eventargs e) <br/>{< br/> int width, height; <br/> width = 0; Height = 0; <br/> cdtinit (ref width, ref height ); <br/>}</P> <p> private void btn_paintcard_click (Object sender, eventargs e) <br/>{< br/> int I, K, left_x, top_y, cardid; <br/> for (k = 0; k <= 3; k ++) <br/> {<br/> for (I = 1; I <= 13; I ++) <br/> {<br/> left_x = 20 + (I-1) * 15; // The width of the overlapping cards is 15 <br/> top_y = 20 + K * 100; // 13 cards in each row. the height is 20 <br/> cardid = (I-1) * 4 + k; // originally 52 cards were numbered <br/> cdtdraw (this. creategraphics (). gethdc (), left_x, top_y, cardid, 0, 9 ); <br/>}</P> <p> private void form=formclosed (Object sender, formclosedeventargs E) <br/>{< br/> cdtterm (); <br/>}</P> <p> private void btn_paintback_click (Object sender, eventargs E) <br/> {<br/> int I, left_x, top_y, backid; <br/> for (I = 0; I <= 11; I ++) // 12 back pictures of cards <br/>{< br/> backid = I; <br/> top_y = 20 + (I & 3) * 100; // if the value is less than or equal to 3, the tail of> 3 is equal to the vertical bars <br/> left_x = 20 + (I> 2) * 80 + 180 + 80; // The left card accounts for 15*12 + 80 = 260, that is, 20 of the rightmost card (implicit card size = 80) <br/> cdtdraw (this. creategraphics (). gethdc (), left_x, top_y, 54 + backid, 1, 9 ); <br/>}</P> <p> private void btn_random?click (Object sender, eventargs E) // The first method implements random card exchange <br/>{< br/> int II, K, left_x, top_y, cardid; <br/> int [] thearray = new int [52]; <br/> random r = new random (); <br/> listbox1.items. clear (); <br/> for (INT I = 0; I <52; I ++) <br/>{< br/> thearray [I] = I + 1; <br/>}< br/> for (INT I = 0; I <52; I ++) // performs 52 random exchanges between two cards <br/>{< br/> int A = R. next (52); // generate a random number of 0 ---> 51 <br/> int B = R. next (52); <br/> int TMP = thearray [a]; <br/> thearray [a] = thearray [B]; <br/> thearray [B] = TMP; <br/>}< br/> for (INT I = 0; I <52; I ++) <br/>{< br/> listbox1.items. add (thearray [I]); <br/> K = (INT) (I/13); <br/> II = I % 13 + 1; <br/> left_x = 20 + (ii-1) * 15; <br/> top_y = 20 + K * 100; <br/> cardid = thearray [I]-1; <br/> cdtdraw (this. creategraphics (). gethdc (), left_x, top_y, cardid, 0, 9 ); <br/>}</P> <p> private void btn_random2_click (Object sender, eventargs E) // The first method implements random card exchange <br/>{< br/> int II, K, left_x, top_y, cardid; <br/> int [] thearray = new int [52]; <br/> int I = 0; <br/> while (I <thearray. length) <br/>{< br/> thearray [I] = ++ I; <br/>}</P> <p> random r = new random (); <br/> listbox1.items. clear (); <br/> while (I> 1) // obtain the final value from 51 --> 1 random forward switch <br/>{< br/> Int J = R. next (I); <br/> int T = thearray [-- I]; <br/> thearray [I] = thearray [J]; <br/> thearray [J] = T; <br/>}</P> <p> for (I = 0; I <thearray. length; ++ I) <br/>{< br/> listbox1.items. add (thearray [I]. tostring (); <br/> K = (INT) (I/13); <br/> II = I % 13 + 1; <br/> left_x = 20 + (ii-1) * 15; <br/> top_y = 20 + K * 100; <br/> cardid = thearray [I]-1; <br/> cdtdraw (this. creategraphics (). gethdc (), left_x, top_y, cardid, 0, 9 ); <br/>}</P> <p >}< br/> compared with designer. CS saves a lot of trouble: </P> <p>

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.