有没有更好的.net方法来检查DateTime是否已经发生'今天'然后是下面的代码?
if ( newsStory.WhenAdded.Day == DateTime.Now.Day &&
newsStory.WhenAdded.Month == DateTime.Now.Month &&
newsStory.WhenAdded.Year == DateTime.Now.Year )
{
// Story happened today
}
else
{
// Story didn't happen today
}
Run Code Online (Sandbox Code Playgroud) 如何从Android摄像头实例中获取当前打开的Android摄像头的ID?我在参数中看不到它,getCameraInfo需要id作为参数.
我是node.js和socket.io的新手,我正在尝试编写一个基于python输出更新网页的小服务器.
最终这将用于温度传感器,所以现在我有一个虚拟脚本,每隔几秒打印一次温度值:
Thermostat.py
import random, time
for x in range(10):
print(str(random.randint(23,28))+" C")
time.sleep(random.uniform(0.4,5))
Run Code Online (Sandbox Code Playgroud)
这是服务器的缩减版本:
Index.js
var sys = require('sys'),
spawn = require('child_process').spawn,
thermostat = spawn('python', ["thermostat.py"]),
app = require('express')(),
http = require('http').Server(app),
io = require('socket.io')(http);
thermostat.stdout.on('data', function (output) {
var temp = String(output);
console.log(temp);
io.sockets.emit('temp-update', { data: temp});
});
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
Run Code Online (Sandbox Code Playgroud)
最后是网页:
的index.html
<!doctype html>
<html>
<head>
<title>Live temperature</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<div id="liveTemp">Loading...</div>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = …Run Code Online (Sandbox Code Playgroud) 我需要能够在此文本周围创建一个黑色背景,而不是在顶部或底部填充.目前,填充是0,但我需要能够以某种方式剪辑它?我的意思是这是当前的文字:

我需要它像这样:

我不介意如何实现这一点,只要它仍然可以在上方和下方具有透明背景.
目前的css是:
padding:0em 0.2em 0em 0.2em;
display:inline-block;
background-color:#000;
color:#FFF;
Run Code Online (Sandbox Code Playgroud)
谢谢!
如何在运行时更改另一个资源字典中使用的资源字典中的颜色?
这是我的设置:
Colours.xaml:
<SolidColorBrush x:Key="themeColour" Color="#16A8EC"/>
Run Code Online (Sandbox Code Playgroud)
Styles.xaml:
<Style x:Key="titleBar" TargetType="Grid">
<Setter Property="Background" Value="{DynamicResource themeColour}"/>
</Style>
Run Code Online (Sandbox Code Playgroud)
Window.xaml
.....
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="res/Styles.xaml"/>
<ResourceDictionary Source="res/Colours.xaml"/>
</ResourceDictionary.MergedDictionaries>
.....
<Grid Style="{DynamicResource titleBar}"></Grid>
Run Code Online (Sandbox Code Playgroud)
代码背后:
Application.Current.Resources["themeColour"] = new SolidColorBrush(newColour);
Run Code Online (Sandbox Code Playgroud)
当代码运行时,网格的颜色不会改变.我不认为Application.Current.Resources ["themeColour"]是指我的solidcolorbrush资源,因为如果我在分配新颜色之前尝试访问它,我会得到一个空对象引用异常.
那么,我该如何访问资源"themeColour"?
我试图在窗口的中心画一个圆圈,我似乎无法把它弄好,应该真的很容易!我的理解是,如果将JPanel设置为JFrame的内容窗格,则默认布局为flowLayout,该绘图应从屏幕的左上角开始为0,0.为了弄清楚发生了什么,我画了一个填充JPanel的蓝色背景,但似乎有这样的边缘:

当窗口小于蓝色矩形时,绘图开始从对面剪切:

这是怎么回事!这是我的代码:
import javax.swing.*;
import java.awt.*;
public class Test extends JFrame {
public static void main(String args[])
{
Test test = new Test();
test.Start();
}
public void Start()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(500, 500);
CirclePanel circlePanel = new CirclePanel();
this.setContentPane(circlePanel);
this.setVisible(true);
}
public class CirclePanel extends JPanel
{
private int radius = 200;
public void paintComponent(Graphics g) {
g.setColor(Color.blue);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(Color.red);
int diameter = radius * 2;
g.fillOval(getX(), getY(), diameter, diameter);
}
public int getX()
{
return (this.getWidth()/2) …Run Code Online (Sandbox Code Playgroud)