zoukankan      html  css  js  c++  java
  • 某些小技巧的技术分享

    分享1:

    需求:输入十进制数x,要求输出三十六进制数y,要求y至少是两位数,如:x=0,1…9,10,y=00,01…09,0z;

             分析:

                     string[] chars = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };

             int vl = (int)value;(注:vl为整数,vl/36是取整)

             string temp = "";

             if (vl < (36 * 36))//count = 2

                 temp = chars[vl / 36] + chars[vl % 36];

             else if (vl < (36 * 36 * 36))//count = 3

                 temp = chars[vl / (36 * 36)] + chars[(vl / 36) % 36] + chars[vl % 36];

             else if (vl < (36 * 36 * 36 * 36))//count = 4

                 temp = chars[vl / (36 * 36 * 36)] + chars[(vl / (36 * 36)) % 36] + chars[(vl / 36) % 36] + chars[vl % 36];

             else if (vl < (36 * 36 * 36 * 36 * 36))//count = 5

                 temp = chars[vl / (36 * 36 * 36 * 36)] + chars[(vl / (36 * 36 * 36)) % 36]+ chars[(vl / (36 * 36)) % 36] + chars[(vl / 36) % 36] + chars[vl % 36];

             .......依次类推

    根据上面的规律,我们可以使用一个while循环进行实现:

    int n=vl;

             int count =1;//记录位数+1

             while (true)

             {

                       if ((n = n / 36) < 36)//计算周期内的位数,直到n的值在0~36内(不包含36)

                       {

                                temp = chars[vl / (int)(Math.Pow(36, count))];//最左边位数值

                                for (int i = count - 1; i > -1; i--)

                                         temp += chars[(vl / (int)(Math.Pow(36, i))) % 36];//从左向右追加位数值

                                break;

                       }

                       count++;

             }

    最后,temp就是所需的结果。(语言:C#)

     

    分享2:

             需求:在winForm中,需要对TextBox输入框进行水印提示;

             分析:对TextBox进行重写操作:

             public partial class WatermarkTextBox : TextBox

        {

            private const uint ECM_FIRST = 0x1500;

            private const uint EM_SETCUEBANNER = ECM_FIRST + 1;

     

            public WatermarkTextBox()

            {

                InitializeComponent();

            }

            [DllImport("user32.dll",CharSet = CharSet.Auto,SetLastError = false)]

            static extern IntPtr SendMessage(IntPtr hWnd, uint Msg ,uint wParam,string lParam);

            private string watermarkText;

            [Description("文本提示")]

            public string WatermarkText

            {

                get { return watermarkText; }

                set

                {

                    watermarkText = value;

                    SetWatermark(watermarkText);

                }

            }

            private void SetWatermark(string watermarkText)

            {

                SendMessage(this.Handle, EM_SETCUEBANNER, 0, watermarkText);

            }

    }

    对此重写方法编译后,我们在设计界面的属性框中就可以找到WatermarkText,直接填写值,使用的WatermarkTextBox控件,就可以看到水印提示了。

  • 相关阅读:
    Chrome 无法登录 GitHub,响应时间过长,可行解决办法
    npm install报错 npm ERR! cb() never called! 检查镜像源!
    Win10 移动文件的时候“卡”在“正在暂停/取消”解决办法
    VS code 彻底关闭插件自动更新功能
    箭头函数 函数中的this指向
    ES6 ES6变量的声明
    范围内的拖拽事件
    div拖拽移动事件
    事件对象的属性 div点击移动事件
    tab切换之循环遍历
  • 原文地址:https://www.cnblogs.com/ysq0908/p/9382980.html
Copyright © 2011-2022 走看看