动态图标在本地工作,而不是从服务器工作 [英] Dynamic Icon Works Locally, Not From Server

查看:67
本文介绍了动态图标在本地工作,而不是从服务器工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢Code Project成员(DK)的帮助,我创建了一个应用程序(Win 7),该应用程序修改了其任务栏图标,并显示了对我们很重要的数值. (注意:在任务栏上,而不是在通知栏上.)

从本地工作站运行程序时,一切正常.但是,当我将.exe放在服务器上并在桌面上为其创建本地快捷方式时,修改后的图标不会出现-只会显示在Visual Studio的应用程序设置"中指定的图标. (如果删除该图标规范,则会得到股票"no-icon"图标.)

我检查了本地防火墙-由于该程序正在运行(仅图标无法显示),我看不到它可能是防火墙,但是请确保我添加了.exe并授予了它访问权限.

所有用户都有权访问服务器上的文件夹.

我在CP上搜索了图标",却什么也没找到. Google也为我干了.

该服务器是Windows Server 2003 R2.
该应用程序是Windows窗体应用程序.

这是处理图标的代码-3个功能;第一个是主要的,第二个格式化图标中显示的数字,第三个选择一种字体,使该数字适合图标的空间:

呼叫:Me.Icon = MakeIcon(CDbl(total))''使用总值更新任务栏图标

功能:

Thanks to help from a Code Project member (D.K.), I have created an app (Win 7) that modifies its taskbar icon, displaying a numerical value that is important to us. (Note: on the Taskbar, not the Notification bar.)

Everything works fine when the program is run from the local workstation. But when I place the .exe on a server and create a local shortcut to it on the desktop, the modified icon does not appear -- only the icon specified in the App settings under Visual Studio. (And if I remove that icon spec, I get the stock "no-icon" icon.)

I checked the local firewall -- since the program runs (only the icon fails to present itself), I couldn''t see how it could be the firewall, but to be sure I added the .exe and granted it access.

All users have access rights to the folder on the server.

I''ve searched CP for "icon" and not found anything; Google came up dry for me as well.

The server is Windows Server 2003 R2.
The app is a Windows Form app.

Here is the code for handling the icon -- 3 functions; the first is the main one, the second formats the number displayed in the icon, and the third picks a font that allows the number to fit in the space of an icon:

Call: Me.Icon = MakeIcon(CDbl(total)) ''updates the taskbar icon with the Total value

Functions:

Private Function MakeIcon(ByVal val As Double) As Icon
        Dim bmp As New Bitmap(64, 64)
        Dim g As Graphics = Graphics.FromImage(bmp)

        'Set background color: if value is positive, DarkBlue; if negative, Maroon.
        g.FillRectangle(IIf(val >= 0, Brushes.DarkBlue, Brushes.Maroon), 0, 0, 64, 64)

        'Pick the largest font that allows the text to fit inside the icon.
        currTaskbarFont = ChooseFont(g, val, bmp)

        Dim s As String = ConvertToKilosAndMegs(val)
        Dim w As SizeF = g.MeasureString(s, currTaskbarFont)

        'Center the text within the icon.
        g.DrawString(s, currTaskbarFont, Brushes.White, _
                     (bmp.Width - w.Width) / 2, (bmp.Height - w.Height) / 2)

        Return Drawing.Icon.FromHandle(bmp.GetHicon)
    End Function

    Private Function ConvertToKilosAndMegs(ByVal val As Double) As String
        Dim sResults As String

        Select Case Math.Abs(val)
            Case Is > 9999.9999  'if >= 10,000, switch to K format
                sResults = (val * 0.001).ToString("F0") & "K"
            Case Is > 9999999.9999  'if >= 10,000,000, switch to M format
                sResults = (val * 0.000001).ToString("F0") & "M"
            Case Else
                sResults = val.ToString("F0")
        End Select

        Return sResults
    End Function

    Private Function ChooseFont(ByRef g As Graphics, ByVal val As Double, ByRef container As Bitmap) As Font
        Dim myFont As Font = fnt(0)
        Try
            For i As Integer = 1 To TASKBAR_FONT_COUNT - 1
                If g.MeasureString(val.ToString("F0"), fnt(i)).Width >= container.Width * 1.1 Then
                    myFont = fnt(i - 1)
                    Exit For
                Else
                    myFont = fnt(i)
                End If
            Next
        Catch ex As Exception
            MsgBox("An error has been encountered in the routine that selects " _
                   & "the optimum font size for the Taskbar Icon." & vbCrLf _
                   & "The icon may not display the Total P&L value properly.", _
                    MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "Error with Taskbar Icon")
        End Try
        Return myFont
    End Function



任何建议将不胜感激!



Any suggestions would be much appreciated!

推荐答案

最终使它起作用了,尽管有些奇怪.我创建了一个踢可执行文件的.BAT文件,然后使用了一个免费软件实用程序,该实用程序将.BAT文件转换为.EXE文件.我能够给这个.EXE一个图标,它以我们希望的方式显示在最终用户工作站上.

仍然不知道为什么在运行应用程序的可执行文件.BAT文件时,图标无法通过,但至少我找到了解决方法.
Finally got it working, albeit in a somewhat odd way. I created a .BAT file that kicks of the executable, then used a freeware utility that converts a .BAT file into an .EXE. I was able to give this .EXE an icon, and it displays on the end user workstation the way we wish it to.

Still don''t know why the icon would not pass through when running the app''s executable sans .BAT file, but at least I found a workaround.


这篇关于动态图标在本地工作,而不是从服务器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆