我需要帮助来替换
字符串中的所有\n(新行)字符,而不是[code] [/ code]标记内的那些字符.我的大脑正在燃烧,我无法用自己解决这个问题:(
例:
test test test
test test test
test
test
[code]some
test
code
[/code]
more text
Run Code Online (Sandbox Code Playgroud)
应该:
test test test<br />
test test test<br />
test<br />
test<br />
<br />
[code]some
test
code
[/code]<br />
<br />
more text<br />
Run Code Online (Sandbox Code Playgroud)
谢谢你的时间.最好的祝福.
我正在尝试使用Visual Studio 2005对我的表单(具有FormBorderStyle = none)执行自定义按钮.我在链接到按钮的ImageList中有我的3个状态按钮图像.
this.btnClose.AutoSize = false;
this.btnClose.BackColor = System.Drawing.Color.Transparent;
this.btnClose.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
this.btnClose.FlatAppearance.BorderSize = 0;
this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnClose.ForeColor = System.Drawing.Color.Transparent;
this.btnClose.ImageKey = "Disabled";
this.btnClose.ImageList = this.imageList1;
this.btnClose.Location = new System.Drawing.Point(368, -5);
this.btnClose.Margin = new System.Windows.Forms.Padding(0);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(31, 31);
this.btnClose.TabIndex = 0;
this.btnClose.UseVisualStyleBackColor = false;
this.btnClose.MouseLeave += new System.EventHandler(this.btnClose_MouseLeave);
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
this.btnClose.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnClose_MouseDown);
this.btnClose.MouseHover += new System.EventHandler(this.btnClose_MouseHover);
private void btnClose_MouseHover(object sender, EventArgs e)
{
btnClose.ImageKey = "enabled";
}
private …Run Code Online (Sandbox Code Playgroud) 我有几个相关的问题:
1)是否可以使我的程序更改文件类型关联,但仅在运行时?你觉得这个行为有什么问题吗?
2)我看到的另一个选项是让用户决定使用我的应用程序打开或恢复默认关联...类似于:"捕获所有.lala文件"或"恢复.lala关联".我怎样才能做到这一点?你认为这是最好的方法是什么?
如何为定义如下的属性设置默认值:
public int MyProperty { get; set; }
Run Code Online (Sandbox Code Playgroud)
那就是在VS2008(代码片段)中使用"prop"[tab] [tab].
是否有可能不退回"旧方式"?:
private int myProperty = 0; // default value
public int MyProperty
{
get { return myProperty; }
set { myProperty = value; }
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的时间.最好的祝福.
我在我的Form构造函数中,在InitializeComponent之后有以下代码:
using (WebClient client = new WebClient())
{
client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(client_DownloadDataCompleted);
client.DownloadDataAsync("http://example.com/version.txt");
}
Run Code Online (Sandbox Code Playgroud)
当我启动表单时,UI不会出现,直到引发client_DownloadDataCompleted.client_DownloadDataCompleted方法为空,因此没有问题.
我做错了什么?如何在不冻结UI的情况下做到这一点?
谢谢你的时间.
最好的祝福.
完整代码:
Program.cs中
using System;
using System.Windows.Forms;
namespace Lala
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Run Code Online (Sandbox Code Playgroud)
Form1.cs的
using System;
using System.Net;
using System.Windows.Forms;
namespace Lala
{
public partial class Form1 : Form
{
WebClient client = new WebClient();
public Form1()
{ …Run Code Online (Sandbox Code Playgroud) 我有这个应用程序需要在受保护的路径中做一些事情(如%PROGRAMFILES%),我知道我应该使用%APPDATA%,但我现在无法改变它.我已经隔离了所有可能需要UAC出现在另一个项目上的东西,这里是一个示例代码:
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
class Class1
{
static void Main(string[] args)
{
try
{
File.CreateText(Path.Combine(Application.StartupPath, "something.txt"));
}
catch (UnauthorizedAccessException ex)
{
MessageBox.Show(ex.Message, "UnauthorizedAccessException", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (args.Length == 0)
{
Process proc = new Process();
proc.StartInfo.FileName = Application.ExecutablePath;
proc.StartInfo.Arguments = "not again";
proc.StartInfo.Verb = "runas";
proc.Start();
}
else
{
MessageBox.Show("Exit to avoid loop.");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以,我从我的主程序中调用这个可执行文件,如果由于未经授权的访问而失败,它将自动启动显示UAC请求.
我的问题是:
1)我不得不将项目输出从DLL转换为EXE,因为我找不到任何方法从DLL请求UAC提升,有没有简单的方法呢?
2)我还注意到有些程序显示了个性化的UAC消息,带有程序徽标和所有这些东西,让我给大家展示一个例子:


我怎么能为我的程序做到这一点?
3)为了避免在使用提升的权限运行时进入循环,它会获得另一个UnauthorizedAccessException我做了那个传递任何args的东西.你会做些什么来实现同样的目标?
我想这就是现在.谢谢你的时间.
我需要更改标题的顺序,我正在使用它:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = context.Request.HttpMethod;
request.UserAgent = context.Request.UserAgent;
Run Code Online (Sandbox Code Playgroud)
输出是:
GET /* HTTP/1.1
User-Agent: My Server
Host: 127.0.0.1:1080
Run Code Online (Sandbox Code Playgroud)
但它应该是
GET /* HTTP/1.1
Host: 127.0.0.1:1080
User-Agent: My Server
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢你的时间.
编辑:也许有一种方法使用其他对象......它也是一种选择
我正在尝试编写一种方法来减少每次调用50%的图像的大小,但我发现了一个问题.有时,我最终会得到一个更大的文件大小,而图像实际上只是它的一半.我正在处理DPI和PixelFormat.我还缺少什么?
感谢您的时间.
public Bitmap ResizeBitmap(Bitmap origBitmap, int nWidth, int nHeight)
{
Bitmap newBitmap = new Bitmap(nWidth, nHeight, origBitmap.PixelFormat);
newBitmap.SetResolution(
origBitmap.HorizontalResolution,
origBitmap.VerticalResolution);
using (Graphics g = Graphics.FromImage((Image)newBitmap))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(origBitmap, 0, 0, nWidth, nHeight);
}
return newBitmap;
}
Run Code Online (Sandbox Code Playgroud)


编辑: 这是缺少的代码:
int width = (int)(bitmap.Width * 0.5f);
int height = (int)(bitmap.Height * 0.5f);
Bitmap resizedBitmap = ResizeBitmap(bitmap, width, height);
resizedBitmap.Save(newFilename);
Run Code Online (Sandbox Code Playgroud)
编辑2: 根据您的评论,这是我找到的解决方案:
private void saveAsJPEG(string savingPath, Bitmap bitmap, long quality)
{
EncoderParameter parameter = new EncoderParameter(Encoder.Compression, quality);
ImageCodecInfo encoder = …Run Code Online (Sandbox Code Playgroud) 我正在使用GridLayout尝试制作标签自动增长而不隐藏其内容的任何内容.这是一个简单的测试代码:每次按下按钮时标签文本都会变大,但只有在我水平调整窗口大小后才会得到正确的布局.有没有办法解决这个问题,而无需调整窗口大小?我想我已经尝试过每一处房产,但我仍然无法使其工作,这让我疯狂!
这就是我得到的

这应该是这样的

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
public class UItest {
protected Shell shell;
private Label label;
public static void main(String[] args) {
try {
UItest window = new UItest();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
protected void createContents() …Run Code Online (Sandbox Code Playgroud) 正如标题所说,我遇到的问题是我需要使用短月份名称格式和年份,日期由AjaxControlToolkit中的MaskedEditExtender验证.DateTime的MMM-yyyy与MaskedEditExtender.Mask ="LLL-9999"不同.
如果我使用en-US语言环境,那就像魅力一样,但是如果我切换到fr-FR那么它将无法工作,因为法语中的短月表示使用4到5个字母(包括点).
有什么想法吗?谢谢.
情况就是这样:我正在开发一个具有以下结构的简单应用程序:
对?
好吧,在FormMain中我有以下功能:
private void DoItInNewThread(ParameterizedThreadStart pParameterizedThreadStart, object pParameters, ThreadPriority pThreadPriority)
{
Thread oThread = new Thread(pParameterizedThreadStart);
oThread.CurrentUICulture = Settings.Instance.Language;
oThread.IsBackground = true;
oThread.Priority = pThreadPriority;
oThread.Name = "?Remote: Background operation";
oThread.Start(pParameters);
}
Run Code Online (Sandbox Code Playgroud)
因此,每次我需要调用位于ComplexFunctions上的耗时方法时,我会执行以下操作:
// This is FormMain.cs
string strSomeParameter = "lala";
DoItInNewThread(new ParameterizedThreadStart(ComplexFunctions.DoSomething), strSomeParameter, ThreadPriority.Normal);
Run Code Online (Sandbox Code Playgroud)
另一个类FormNotification,它是一个向用户显示进程信息的表单.可以从FormMain或ComplexFunctions调用此FormNotification.例:
// This is ComplexFunctions.cs
public void DoSomething(string pSomeParameter)
{
// Imagine some time consuming task
FormNotification formNotif = new FormNotification();
formNotif.Notify();
}
Run Code Online (Sandbox Code Playgroud)
FormNotify有一个计时器,因此,在10秒后关闭表单.我没有使用formNotif.ShowDialog,因为我不想把焦点放在这个Form上.您可以查看此链接以查看我在通知中所做的事情.
好吧,这就是问题所在:当我从 …
我是一个php人,但我必须在JSP中做一些小项目.我想知道JSP中是否有相当于htmlentities函数(php).